tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsPreloadedStream.h (1774B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      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 /**
      7 * This class allows you to prefix an existing nsIAsyncInputStream
      8 * with a preloaded block of data known at construction time by wrapping the
      9 * two data sources into a new nsIAsyncInputStream. Readers of the new
     10 * stream initially see the preloaded data and when that has been exhausted
     11 * they automatically read from the wrapped stream.
     12 *
     13 * It is used by nsHttpConnection when it has over buffered while reading from
     14 * the HTTP input socket and accidentally consumed data that belongs to
     15 * a different protocol via the HTTP Upgrade mechanism. That over-buffered
     16 * data is preloaded together with the input socket to form the new input socket
     17 * given to the new protocol handler.
     18 */
     19 
     20 #ifndef nsPreloadedStream_h__
     21 #define nsPreloadedStream_h__
     22 
     23 #include "nsIAsyncInputStream.h"
     24 #include "nsCOMPtr.h"
     25 #include "mozilla/DataMutex.h"
     26 
     27 namespace mozilla {
     28 namespace net {
     29 
     30 class nsPreloadedStream final : public nsIAsyncInputStream,
     31                                public nsIInputStreamCallback {
     32 public:
     33  NS_DECL_THREADSAFE_ISUPPORTS
     34  NS_DECL_NSIINPUTSTREAM
     35  NS_DECL_NSIASYNCINPUTSTREAM
     36  NS_DECL_NSIINPUTSTREAMCALLBACK
     37 
     38  nsPreloadedStream(nsIAsyncInputStream* aStream, const char* data,
     39                    uint32_t datalen);
     40 
     41 private:
     42  ~nsPreloadedStream();
     43 
     44  nsCOMPtr<nsIAsyncInputStream> mStream;
     45 
     46  char* mBuf;
     47  uint32_t mOffset;
     48  uint32_t mLen;
     49 
     50  DataMutex<nsCOMPtr<nsIInputStreamCallback>> mCallback;
     51 };
     52 
     53 }  // namespace net
     54 }  // namespace mozilla
     55 
     56 #endif