1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsPreloadedStream.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * This class allows you to prefix an existing nsIAsyncInputStream 1.11 + * with a preloaded block of data known at construction time by wrapping the 1.12 + * two data sources into a new nsIAsyncInputStream. Readers of the new 1.13 + * stream initially see the preloaded data and when that has been exhausted 1.14 + * they automatically read from the wrapped stream. 1.15 + * 1.16 + * It is used by nsHttpConnection when it has over buffered while reading from 1.17 + * the HTTP input socket and accidentally consumed data that belongs to 1.18 + * a different protocol via the HTTP Upgrade mechanism. That over-buffered 1.19 + * data is preloaded together with the input socket to form the new input socket 1.20 + * given to the new protocol handler. 1.21 +*/ 1.22 + 1.23 +#ifndef nsPreloadedStream_h__ 1.24 +#define nsPreloadedStream_h__ 1.25 + 1.26 +#include "nsIAsyncInputStream.h" 1.27 +#include "nsCOMPtr.h" 1.28 +#include "mozilla/Attributes.h" 1.29 + 1.30 +namespace mozilla { 1.31 +namespace net { 1.32 + 1.33 +class nsPreloadedStream MOZ_FINAL : public nsIAsyncInputStream 1.34 +{ 1.35 + public: 1.36 + NS_DECL_THREADSAFE_ISUPPORTS 1.37 + NS_DECL_NSIINPUTSTREAM 1.38 + NS_DECL_NSIASYNCINPUTSTREAM 1.39 + 1.40 + nsPreloadedStream(nsIAsyncInputStream *aStream, 1.41 + const char *data, uint32_t datalen); 1.42 +private: 1.43 + ~nsPreloadedStream(); 1.44 + 1.45 + nsCOMPtr<nsIAsyncInputStream> mStream; 1.46 + 1.47 + char *mBuf; 1.48 + uint32_t mOffset; 1.49 + uint32_t mLen; 1.50 +}; 1.51 + 1.52 +} // namespace net 1.53 +} // namespace mozilla 1.54 + 1.55 +#endif