netwerk/base/src/nsPreloadedStream.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: 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/. */
     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 */
    20 #ifndef nsPreloadedStream_h__
    21 #define nsPreloadedStream_h__
    23 #include "nsIAsyncInputStream.h"
    24 #include "nsCOMPtr.h"
    25 #include "mozilla/Attributes.h"
    27 namespace mozilla {
    28 namespace net {
    30 class nsPreloadedStream MOZ_FINAL : public nsIAsyncInputStream
    31 {
    32  public:
    33     NS_DECL_THREADSAFE_ISUPPORTS
    34     NS_DECL_NSIINPUTSTREAM
    35     NS_DECL_NSIASYNCINPUTSTREAM
    37     nsPreloadedStream(nsIAsyncInputStream *aStream, 
    38                       const char *data, uint32_t datalen);
    39 private:
    40     ~nsPreloadedStream();
    42     nsCOMPtr<nsIAsyncInputStream> mStream;
    44     char *mBuf;
    45     uint32_t mOffset;
    46     uint32_t mLen;
    47 };
    49 } // namespace net
    50 } // namespace mozilla
    52 #endif

mercurial