/* 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/. */
//----------------------------------------------------------------------------- // nsInputStreamTransport // // Implements nsIInputStream as a wrapper around the real input stream. This // allows the transport to support seeking, range-limiting, progress reporting, // and close-when-done semantics while utilizing NS_AsyncCopy. //-----------------------------------------------------------------------------
class nsInputStreamTransport : public nsITransport, public nsIAsyncInputStream, public nsIInputStreamCallback { public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSITRANSPORT
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIASYNCINPUTSTREAM
NS_DECL_NSIINPUTSTREAMCALLBACK
// This value is protected by mutex.
nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback;
nsCOMPtr<nsIAsyncInputStream> mPipeIn;
// while the copy is active, these members may only be accessed from the // nsIInputStream implementation.
nsCOMPtr<nsITransportEventSink> mEventSink;
nsCOMPtr<nsIInputStream> mSource;
// It can be null.
nsCOMPtr<nsIAsyncInputStream> mAsyncSource;
int64_t mOffset{0}; constbool mCloseWhenDone;
// this variable serves as a lock to prevent the state of the transport // from being modified once the copy is in progress. bool mInProgress{false};
};
// XXX if the caller requests an unbuffered stream, then perhaps // we'd want to simply return mSource; however, then we would // not be reading mSource on a background thread. is this ok?
nsStreamTransportService::~nsStreamTransportService() {
NS_ASSERTION(!mPool, "thread pool wasn't shutdown");
}
nsresult nsStreamTransportService::Init() { // Can't be used multithreaded before this
MOZ_PUSH_IGNORE_THREAD_SAFETY
MOZ_ASSERT(!mPool);
mPool = new nsThreadPool();
// Configure the pool
mPool->SetName("StreamTrans"_ns); // TODO: Make these settings configurable.
mPool->SetThreadLimit(25);
mPool->SetIdleThreadLimit(4);
mPool->SetIdleThreadMaximumTimeout(30 * 1000);
mPool->SetIdleThreadGraceTimeout(500);
MOZ_POP_THREAD_SAFETY
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.