netwerk/base/src/nsInputStreamPump.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsInputStreamPump_h__
michael@0 7 #define nsInputStreamPump_h__
michael@0 8
michael@0 9 #include "nsIInputStreamPump.h"
michael@0 10 #include "nsIAsyncInputStream.h"
michael@0 11 #include "nsIThreadRetargetableRequest.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13 #include "mozilla/Attributes.h"
michael@0 14 #include "mozilla/ReentrantMonitor.h"
michael@0 15
michael@0 16 class nsIInputStream;
michael@0 17 class nsILoadGroup;
michael@0 18 class nsIStreamListener;
michael@0 19
michael@0 20 class nsInputStreamPump MOZ_FINAL : public nsIInputStreamPump
michael@0 21 , public nsIInputStreamCallback
michael@0 22 , public nsIThreadRetargetableRequest
michael@0 23 {
michael@0 24 public:
michael@0 25 typedef mozilla::ReentrantMonitorAutoEnter ReentrantMonitorAutoEnter;
michael@0 26 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 27 NS_DECL_NSIREQUEST
michael@0 28 NS_DECL_NSIINPUTSTREAMPUMP
michael@0 29 NS_DECL_NSIINPUTSTREAMCALLBACK
michael@0 30 NS_DECL_NSITHREADRETARGETABLEREQUEST
michael@0 31
michael@0 32 nsInputStreamPump();
michael@0 33 ~nsInputStreamPump();
michael@0 34
michael@0 35 static NS_HIDDEN_(nsresult)
michael@0 36 Create(nsInputStreamPump **result,
michael@0 37 nsIInputStream *stream,
michael@0 38 int64_t streamPos = -1,
michael@0 39 int64_t streamLen = -1,
michael@0 40 uint32_t segsize = 0,
michael@0 41 uint32_t segcount = 0,
michael@0 42 bool closeWhenDone = false);
michael@0 43
michael@0 44 typedef void (*PeekSegmentFun)(void *closure, const uint8_t *buf,
michael@0 45 uint32_t bufLen);
michael@0 46 /**
michael@0 47 * Peek into the first chunk of data that's in the stream. Note that this
michael@0 48 * method will not call the callback when there is no data in the stream.
michael@0 49 * The callback will be called at most once.
michael@0 50 *
michael@0 51 * The data from the stream will not be consumed, i.e. the pump's listener
michael@0 52 * can still read all the data.
michael@0 53 *
michael@0 54 * Do not call before asyncRead. Do not call after onStopRequest.
michael@0 55 */
michael@0 56 NS_HIDDEN_(nsresult) PeekStream(PeekSegmentFun callback, void *closure);
michael@0 57
michael@0 58 /**
michael@0 59 * Dispatched (to the main thread) by OnStateStop if it's called off main
michael@0 60 * thread. Updates mState based on return value of OnStateStop.
michael@0 61 */
michael@0 62 nsresult CallOnStateStop();
michael@0 63
michael@0 64 protected:
michael@0 65
michael@0 66 enum {
michael@0 67 STATE_IDLE,
michael@0 68 STATE_START,
michael@0 69 STATE_TRANSFER,
michael@0 70 STATE_STOP
michael@0 71 };
michael@0 72
michael@0 73 nsresult EnsureWaiting();
michael@0 74 uint32_t OnStateStart();
michael@0 75 uint32_t OnStateTransfer();
michael@0 76 uint32_t OnStateStop();
michael@0 77
michael@0 78 uint32_t mState;
michael@0 79 nsCOMPtr<nsILoadGroup> mLoadGroup;
michael@0 80 nsCOMPtr<nsIStreamListener> mListener;
michael@0 81 nsCOMPtr<nsISupports> mListenerContext;
michael@0 82 nsCOMPtr<nsIEventTarget> mTargetThread;
michael@0 83 nsCOMPtr<nsIInputStream> mStream;
michael@0 84 nsCOMPtr<nsIAsyncInputStream> mAsyncStream;
michael@0 85 uint64_t mStreamOffset;
michael@0 86 uint64_t mStreamLength;
michael@0 87 uint32_t mSegSize;
michael@0 88 uint32_t mSegCount;
michael@0 89 nsresult mStatus;
michael@0 90 uint32_t mSuspendCount;
michael@0 91 uint32_t mLoadFlags;
michael@0 92 bool mIsPending;
michael@0 93 // True while in OnInputStreamReady, calling OnStateStart, OnStateTransfer
michael@0 94 // and OnStateStop. Used to prevent calls to AsyncWait during callbacks.
michael@0 95 bool mProcessingCallbacks;
michael@0 96 // True if waiting on the "input stream ready" callback.
michael@0 97 bool mWaitingForInputStreamReady;
michael@0 98 bool mCloseWhenDone;
michael@0 99 bool mRetargeting;
michael@0 100 // Protects state/member var accesses across multiple threads.
michael@0 101 mozilla::ReentrantMonitor mMonitor;
michael@0 102 };
michael@0 103
michael@0 104 #endif // !nsInputStreamChannel_h__

mercurial