2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-01-13 12:11:01 +03:00
|
|
|
|
|
|
|
#ifndef nsBufferedStreams_h__
|
|
|
|
#define nsBufferedStreams_h__
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsIBufferedStreams.h"
|
2000-01-13 12:11:01 +03:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
2004-07-20 02:00:03 +04:00
|
|
|
#include "nsISafeOutputStream.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsISeekableStream.h"
|
2001-07-31 23:05:34 +04:00
|
|
|
#include "nsIStreamBufferAccess.h"
|
2000-01-13 12:11:01 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-08-23 06:13:54 +04:00
|
|
|
#include "nsIIPCSerializableInputStream.h"
|
2017-05-02 20:32:42 +03:00
|
|
|
#include "nsIAsyncInputStream.h"
|
2017-12-13 03:38:19 +03:00
|
|
|
#include "nsICloneableInputStream.h"
|
2018-05-23 08:12:35 +03:00
|
|
|
#include "nsIInputStreamLength.h"
|
2018-04-10 18:33:08 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-10-21 22:36:13 +04:00
|
|
|
|
2000-01-13 12:11:01 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
class nsBufferedStream : public nsISeekableStream {
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSISEEKABLESTREAM
|
|
|
|
NS_DECL_NSITELLABLESTREAM
|
2000-01-13 12:11:01 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsBufferedStream();
|
2000-01-13 12:11:01 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsresult Close();
|
2000-08-22 11:03:33 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
protected:
|
|
|
|
virtual ~nsBufferedStream();
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsresult Init(nsISupports* stream, uint32_t bufferSize);
|
|
|
|
nsresult GetData(nsISupports** aResult);
|
|
|
|
NS_IMETHOD Fill() = 0;
|
|
|
|
NS_IMETHOD Flush() = 0;
|
2000-01-13 12:11:01 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
uint32_t mBufferSize;
|
|
|
|
char* mBuffer;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
// mBufferStartOffset is the offset relative to the start of mStream.
|
|
|
|
int64_t mBufferStartOffset;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
// mCursor is the read cursor for input streams, or write cursor for
|
|
|
|
// output streams, and is relative to mBufferStartOffset.
|
|
|
|
uint32_t mCursor;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
// mFillPoint is the amount available in the buffer for input streams,
|
|
|
|
// or the high watermark of bytes written into the buffer, and therefore
|
|
|
|
// is relative to mBufferStartOffset.
|
|
|
|
uint32_t mFillPoint;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsISupports* mStream; // cast to appropriate subclass
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-22 00:51:34 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
bool mBufferDisabled;
|
|
|
|
bool mEOF; // True if mStream is at EOF
|
|
|
|
uint8_t mGetBufferCount;
|
2000-01-13 12:11:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
class nsBufferedInputStream final : public nsBufferedStream,
|
|
|
|
public nsIBufferedInputStream,
|
|
|
|
public nsIStreamBufferAccess,
|
|
|
|
public nsIIPCSerializableInputStream,
|
|
|
|
public nsIAsyncInputStream,
|
|
|
|
public nsIInputStreamCallback,
|
|
|
|
public nsICloneableInputStream,
|
|
|
|
public nsIInputStreamLength,
|
|
|
|
public nsIAsyncInputStreamLength,
|
|
|
|
public nsIInputStreamLengthCallback {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSIBUFFEREDINPUTSTREAM
|
|
|
|
NS_DECL_NSISTREAMBUFFERACCESS
|
|
|
|
NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAM
|
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
|
|
|
NS_DECL_NSICLONEABLEINPUTSTREAM
|
|
|
|
NS_DECL_NSIINPUTSTREAMLENGTH
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAMLENGTH
|
|
|
|
NS_DECL_NSIINPUTSTREAMLENGTHCALLBACK
|
|
|
|
|
|
|
|
nsBufferedInputStream();
|
|
|
|
|
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
|
|
|
nsIInputStream* Source() { return (nsIInputStream*)mStream; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsBufferedInputStream() = default;
|
|
|
|
|
|
|
|
NS_IMETHOD Fill() override;
|
|
|
|
NS_IMETHOD Flush() override { return NS_OK; } // no-op for input streams
|
|
|
|
|
|
|
|
mozilla::Mutex mMutex;
|
|
|
|
|
|
|
|
// This value is protected by mutex.
|
|
|
|
nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback;
|
|
|
|
|
|
|
|
// This value is protected by mutex.
|
|
|
|
nsCOMPtr<nsIInputStreamLengthCallback> mAsyncInputStreamLengthCallback;
|
|
|
|
|
|
|
|
bool mIsIPCSerializable;
|
|
|
|
bool mIsAsyncInputStream;
|
|
|
|
bool mIsCloneableInputStream;
|
|
|
|
bool mIsInputStreamLength;
|
|
|
|
bool mIsAsyncInputStreamLength;
|
2000-01-13 12:11:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
class nsBufferedOutputStream : public nsBufferedStream,
|
|
|
|
public nsISafeOutputStream,
|
|
|
|
public nsIBufferedOutputStream,
|
|
|
|
public nsIStreamBufferAccess {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIOUTPUTSTREAM
|
|
|
|
NS_DECL_NSISAFEOUTPUTSTREAM
|
|
|
|
NS_DECL_NSIBUFFEREDOUTPUTSTREAM
|
|
|
|
NS_DECL_NSISTREAMBUFFERACCESS
|
2000-01-13 12:11:01 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsBufferedOutputStream() : nsBufferedStream() {}
|
2000-01-13 12:11:01 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
2000-01-13 12:11:01 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsIOutputStream* Sink() { return (nsIOutputStream*)mStream; }
|
2000-02-04 10:31:43 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
protected:
|
|
|
|
virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); }
|
2014-07-09 01:23:18 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
NS_IMETHOD Fill() override { return NS_OK; } // no-op for output streams
|
2004-07-20 02:00:03 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
nsCOMPtr<nsISafeOutputStream> mSafeStream; // QI'd from mStream
|
2000-01-13 12:11:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif // nsBufferedStreams_h__
|