|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsHttpPipeline_h__ |
|
7 #define nsHttpPipeline_h__ |
|
8 |
|
9 #include "nsAHttpConnection.h" |
|
10 #include "nsAHttpTransaction.h" |
|
11 #include "nsTArray.h" |
|
12 #include "nsCOMPtr.h" |
|
13 |
|
14 class nsIInputStream; |
|
15 class nsIOutputStream; |
|
16 |
|
17 namespace mozilla { namespace net { |
|
18 |
|
19 class nsHttpPipeline : public nsAHttpConnection |
|
20 , public nsAHttpTransaction |
|
21 , public nsAHttpSegmentReader |
|
22 { |
|
23 public: |
|
24 NS_DECL_THREADSAFE_ISUPPORTS |
|
25 NS_DECL_NSAHTTPCONNECTION(mConnection) |
|
26 NS_DECL_NSAHTTPTRANSACTION |
|
27 NS_DECL_NSAHTTPSEGMENTREADER |
|
28 |
|
29 nsHttpPipeline(); |
|
30 virtual ~nsHttpPipeline(); |
|
31 |
|
32 bool ResponseTimeoutEnabled() const MOZ_OVERRIDE MOZ_FINAL { |
|
33 return true; |
|
34 } |
|
35 |
|
36 uint32_t RequestDepth() { return mRequestQ.Length(); } |
|
37 |
|
38 private: |
|
39 nsresult FillSendBuf(); |
|
40 |
|
41 static NS_METHOD ReadFromPipe(nsIInputStream *, void *, const char *, |
|
42 uint32_t, uint32_t, uint32_t *); |
|
43 |
|
44 void ShuffleTransOrder(uint32_t); |
|
45 |
|
46 // convenience functions |
|
47 nsAHttpTransaction *Request(int32_t i) |
|
48 { |
|
49 if (mRequestQ.Length() == 0) |
|
50 return nullptr; |
|
51 |
|
52 return mRequestQ[i]; |
|
53 } |
|
54 nsAHttpTransaction *Response(int32_t i) |
|
55 { |
|
56 if (mResponseQ.Length() == 0) |
|
57 return nullptr; |
|
58 |
|
59 return mResponseQ[i]; |
|
60 } |
|
61 |
|
62 // overload of nsAHttpTransaction::QueryPipeline() |
|
63 nsHttpPipeline *QueryPipeline(); |
|
64 |
|
65 nsAHttpConnection *mConnection; |
|
66 nsTArray<nsAHttpTransaction*> mRequestQ; // array of transactions |
|
67 nsTArray<nsAHttpTransaction*> mResponseQ; // array of transactions |
|
68 nsresult mStatus; |
|
69 |
|
70 // these flags indicate whether or not the first request or response |
|
71 // is partial. a partial request means that Request(0) has been |
|
72 // partially written out to the socket. a partial response means |
|
73 // that Response(0) has been partially read in from the socket. |
|
74 bool mRequestIsPartial; |
|
75 bool mResponseIsPartial; |
|
76 |
|
77 // indicates whether or not the pipeline has been explicitly closed. |
|
78 bool mClosed; |
|
79 |
|
80 // indicates whether or not a true pipeline (more than 1 request without |
|
81 // a synchronous response) has been formed. |
|
82 bool mUtilizedPipeline; |
|
83 |
|
84 // used when calling ReadSegments/WriteSegments on a transaction. |
|
85 nsAHttpSegmentReader *mReader; |
|
86 |
|
87 // send buffer |
|
88 nsCOMPtr<nsIInputStream> mSendBufIn; |
|
89 nsCOMPtr<nsIOutputStream> mSendBufOut; |
|
90 |
|
91 // the push back buffer. not exceeding nsIOService::gDefaultSegmentSize bytes. |
|
92 char *mPushBackBuf; |
|
93 uint32_t mPushBackLen; |
|
94 uint32_t mPushBackMax; |
|
95 |
|
96 // The number of transactions completed on this pipeline. |
|
97 uint32_t mHttp1xTransactionCount; |
|
98 |
|
99 // For support of OnTransportStatus() |
|
100 uint64_t mReceivingFromProgress; |
|
101 uint64_t mSendingToProgress; |
|
102 bool mSuppressSendEvents; |
|
103 }; |
|
104 |
|
105 }} // namespace mozilla::net |
|
106 |
|
107 #endif // nsHttpPipeline_h__ |