nsPreloadedStream.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. * This class allows you to prefix an existing nsIAsyncInputStream
  7. * with a preloaded block of data known at construction time by wrapping the
  8. * two data sources into a new nsIAsyncInputStream. Readers of the new
  9. * stream initially see the preloaded data and when that has been exhausted
  10. * they automatically read from the wrapped stream.
  11. *
  12. * It is used by nsHttpConnection when it has over buffered while reading from
  13. * the HTTP input socket and accidentally consumed data that belongs to
  14. * a different protocol via the HTTP Upgrade mechanism. That over-buffered
  15. * data is preloaded together with the input socket to form the new input socket
  16. * given to the new protocol handler.
  17. */
  18. #ifndef nsPreloadedStream_h__
  19. #define nsPreloadedStream_h__
  20. #include "nsIAsyncInputStream.h"
  21. #include "nsCOMPtr.h"
  22. #include "mozilla/Attributes.h"
  23. namespace mozilla {
  24. namespace net {
  25. class nsPreloadedStream final : public nsIAsyncInputStream
  26. {
  27. public:
  28. NS_DECL_THREADSAFE_ISUPPORTS
  29. NS_DECL_NSIINPUTSTREAM
  30. NS_DECL_NSIASYNCINPUTSTREAM
  31. nsPreloadedStream(nsIAsyncInputStream *aStream,
  32. const char *data, uint32_t datalen);
  33. private:
  34. ~nsPreloadedStream();
  35. nsCOMPtr<nsIAsyncInputStream> mStream;
  36. char *mBuf;
  37. uint32_t mOffset;
  38. uint32_t mLen;
  39. };
  40. } // namespace net
  41. } // namespace mozilla
  42. #endif