netwerk/base/src/nsPreloadedStream.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:d20861f6b134
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/. */
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/Attributes.h"
26
27 namespace mozilla {
28 namespace net {
29
30 class nsPreloadedStream MOZ_FINAL : public nsIAsyncInputStream
31 {
32 public:
33 NS_DECL_THREADSAFE_ISUPPORTS
34 NS_DECL_NSIINPUTSTREAM
35 NS_DECL_NSIASYNCINPUTSTREAM
36
37 nsPreloadedStream(nsIAsyncInputStream *aStream,
38 const char *data, uint32_t datalen);
39 private:
40 ~nsPreloadedStream();
41
42 nsCOMPtr<nsIAsyncInputStream> mStream;
43
44 char *mBuf;
45 uint32_t mOffset;
46 uint32_t mLen;
47 };
48
49 } // namespace net
50 } // namespace mozilla
51
52 #endif

mercurial