michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * This class allows you to prefix an existing nsIAsyncInputStream michael@0: * with a preloaded block of data known at construction time by wrapping the michael@0: * two data sources into a new nsIAsyncInputStream. Readers of the new michael@0: * stream initially see the preloaded data and when that has been exhausted michael@0: * they automatically read from the wrapped stream. michael@0: * michael@0: * It is used by nsHttpConnection when it has over buffered while reading from michael@0: * the HTTP input socket and accidentally consumed data that belongs to michael@0: * a different protocol via the HTTP Upgrade mechanism. That over-buffered michael@0: * data is preloaded together with the input socket to form the new input socket michael@0: * given to the new protocol handler. michael@0: */ michael@0: michael@0: #ifndef nsPreloadedStream_h__ michael@0: #define nsPreloadedStream_h__ michael@0: michael@0: #include "nsIAsyncInputStream.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: class nsPreloadedStream MOZ_FINAL : public nsIAsyncInputStream michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIINPUTSTREAM michael@0: NS_DECL_NSIASYNCINPUTSTREAM michael@0: michael@0: nsPreloadedStream(nsIAsyncInputStream *aStream, michael@0: const char *data, uint32_t datalen); michael@0: private: michael@0: ~nsPreloadedStream(); michael@0: michael@0: nsCOMPtr mStream; michael@0: michael@0: char *mBuf; michael@0: uint32_t mOffset; michael@0: uint32_t mLen; michael@0: }; michael@0: michael@0: } // namespace net michael@0: } // namespace mozilla michael@0: michael@0: #endif