Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; 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 | /** |
michael@0 | 7 | * This class allows you to prefix an existing nsIAsyncInputStream |
michael@0 | 8 | * with a preloaded block of data known at construction time by wrapping the |
michael@0 | 9 | * two data sources into a new nsIAsyncInputStream. Readers of the new |
michael@0 | 10 | * stream initially see the preloaded data and when that has been exhausted |
michael@0 | 11 | * they automatically read from the wrapped stream. |
michael@0 | 12 | * |
michael@0 | 13 | * It is used by nsHttpConnection when it has over buffered while reading from |
michael@0 | 14 | * the HTTP input socket and accidentally consumed data that belongs to |
michael@0 | 15 | * a different protocol via the HTTP Upgrade mechanism. That over-buffered |
michael@0 | 16 | * data is preloaded together with the input socket to form the new input socket |
michael@0 | 17 | * given to the new protocol handler. |
michael@0 | 18 | */ |
michael@0 | 19 | |
michael@0 | 20 | #ifndef nsPreloadedStream_h__ |
michael@0 | 21 | #define nsPreloadedStream_h__ |
michael@0 | 22 | |
michael@0 | 23 | #include "nsIAsyncInputStream.h" |
michael@0 | 24 | #include "nsCOMPtr.h" |
michael@0 | 25 | #include "mozilla/Attributes.h" |
michael@0 | 26 | |
michael@0 | 27 | namespace mozilla { |
michael@0 | 28 | namespace net { |
michael@0 | 29 | |
michael@0 | 30 | class nsPreloadedStream MOZ_FINAL : public nsIAsyncInputStream |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 34 | NS_DECL_NSIINPUTSTREAM |
michael@0 | 35 | NS_DECL_NSIASYNCINPUTSTREAM |
michael@0 | 36 | |
michael@0 | 37 | nsPreloadedStream(nsIAsyncInputStream *aStream, |
michael@0 | 38 | const char *data, uint32_t datalen); |
michael@0 | 39 | private: |
michael@0 | 40 | ~nsPreloadedStream(); |
michael@0 | 41 | |
michael@0 | 42 | nsCOMPtr<nsIAsyncInputStream> mStream; |
michael@0 | 43 | |
michael@0 | 44 | char *mBuf; |
michael@0 | 45 | uint32_t mOffset; |
michael@0 | 46 | uint32_t mLen; |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | } // namespace net |
michael@0 | 50 | } // namespace mozilla |
michael@0 | 51 | |
michael@0 | 52 | #endif |