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

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

mercurial