2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2001-03-02 06:10:00 +00:00
|
|
|
|
2010-02-23 18:13:18 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "prlog.h"
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2012-06-05 23:51:58 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2001-03-02 06:10:00 +00:00
|
|
|
#include "nsIInputStreamTee.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2010-02-23 18:13:18 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIEventTarget.h"
|
|
|
|
#include "nsThreadUtils.h"
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2010-02-23 18:13:18 +00:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo* gInputStreamTeeLog = PR_NewLogModule("nsInputStreamTee");
|
|
|
|
#define LOG(args) PR_LOG(gInputStreamTeeLog, PR_LOG_DEBUG, args)
|
|
|
|
#else
|
|
|
|
#define LOG(args)
|
|
|
|
#endif
|
2001-03-02 06:10:00 +00:00
|
|
|
|
2012-06-05 23:51:58 +00:00
|
|
|
class nsInputStreamTee MOZ_FINAL : public nsIInputStreamTee
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSIINPUTSTREAMTEE
|
|
|
|
|
|
|
|
nsInputStreamTee();
|
2010-09-07 22:39:28 +00:00
|
|
|
bool SinkIsValid();
|
|
|
|
void InvalidateSink();
|
2001-03-02 06:10:00 +00:00
|
|
|
|
|
|
|
private:
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
~nsInputStreamTee() {}
|
2004-01-15 06:14:18 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult TeeSegment(const char *buf, uint32_t count);
|
2010-09-07 22:39:28 +00:00
|
|
|
|
2001-03-02 06:10:00 +00:00
|
|
|
static NS_METHOD WriteSegmentFun(nsIInputStream *, void *, const char *,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t, uint32_t, uint32_t *);
|
2001-03-02 06:10:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIInputStream> mSource;
|
|
|
|
nsCOMPtr<nsIOutputStream> mSink;
|
2010-02-23 18:13:18 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> mEventTarget;
|
2001-03-02 06:10:00 +00:00
|
|
|
nsWriteSegmentFun mWriter; // for implementing ReadSegments
|
2010-09-07 22:39:28 +00:00
|
|
|
void *mClosure; // for implementing ReadSegments
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
nsAutoPtr<Mutex> mLock; // synchronize access to mSinkIsValid
|
2010-09-07 22:39:28 +00:00
|
|
|
bool mSinkIsValid; // False if TeeWriteEvent fails
|
2001-03-02 06:10:00 +00:00
|
|
|
};
|
|
|
|
|
2010-02-23 18:13:18 +00:00
|
|
|
class nsInputStreamTeeWriteEvent : public nsRunnable {
|
|
|
|
public:
|
2010-09-07 22:39:28 +00:00
|
|
|
// aTee's lock is held across construction of this object
|
2012-08-22 15:56:38 +00:00
|
|
|
nsInputStreamTeeWriteEvent(const char *aBuf, uint32_t aCount,
|
2010-09-07 22:39:28 +00:00
|
|
|
nsIOutputStream *aSink,
|
|
|
|
nsInputStreamTee *aTee)
|
2010-02-23 18:13:18 +00:00
|
|
|
{
|
|
|
|
// copy the buffer - will be free'd by dtor
|
|
|
|
mBuf = (char *)malloc(aCount);
|
|
|
|
if (mBuf) memcpy(mBuf, (char *)aBuf, aCount);
|
|
|
|
mCount = aCount;
|
|
|
|
mSink = aSink;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isNonBlocking;
|
2010-02-23 18:13:18 +00:00
|
|
|
mSink->IsNonBlocking(&isNonBlocking);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION(isNonBlocking == false, "mSink is nonblocking");
|
2010-09-07 22:39:28 +00:00
|
|
|
mTee = aTee;
|
2010-02-23 18:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
if (!mBuf) {
|
|
|
|
NS_WARNING("nsInputStreamTeeWriteEvent::Run() "
|
2010-09-07 22:39:28 +00:00
|
|
|
"memory not allocated\n");
|
2010-02-23 18:13:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(mSink, "mSink is null!");
|
|
|
|
|
2010-09-07 22:39:28 +00:00
|
|
|
// The output stream could have been invalidated between when
|
|
|
|
// this event was dispatched and now, so check before writing.
|
|
|
|
if (!mTee->SinkIsValid()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:18 +00:00
|
|
|
LOG(("nsInputStreamTeeWriteEvent::Run() [%p]"
|
2010-09-07 22:39:28 +00:00
|
|
|
"will write %u bytes to %p\n",
|
|
|
|
this, mCount, mSink.get()));
|
2010-02-23 18:13:18 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t totalBytesWritten = 0;
|
2010-02-23 18:13:18 +00:00
|
|
|
while (mCount) {
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bytesWritten = 0;
|
2010-02-23 18:13:18 +00:00
|
|
|
rv = mSink->Write(mBuf + totalBytesWritten, mCount, &bytesWritten);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("nsInputStreamTeeWriteEvent::Run[%p] error %x in writing",
|
|
|
|
this,rv));
|
2010-09-07 22:39:28 +00:00
|
|
|
mTee->InvalidateSink();
|
2010-02-23 18:13:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
totalBytesWritten += bytesWritten;
|
|
|
|
NS_ASSERTION(bytesWritten <= mCount, "wrote too much");
|
|
|
|
mCount -= bytesWritten;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsInputStreamTeeWriteEvent()
|
|
|
|
{
|
|
|
|
if (mBuf) free(mBuf);
|
2012-07-30 14:20:58 +00:00
|
|
|
mBuf = nullptr;
|
2010-02-23 18:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
char *mBuf;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mCount;
|
2010-02-23 18:13:18 +00:00
|
|
|
nsCOMPtr<nsIOutputStream> mSink;
|
2010-09-07 22:39:28 +00:00
|
|
|
// back pointer to the tee that created this runnable
|
|
|
|
nsRefPtr<nsInputStreamTee> mTee;
|
2010-02-23 18:13:18 +00:00
|
|
|
};
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsInputStreamTee::nsInputStreamTee(): mLock(nullptr)
|
2010-09-07 22:39:28 +00:00
|
|
|
, mSinkIsValid(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsInputStreamTee::SinkIsValid()
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(*mLock);
|
2010-09-07 22:39:28 +00:00
|
|
|
return mSinkIsValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsInputStreamTee::InvalidateSink()
|
|
|
|
{
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
MutexAutoLock lock(*mLock);
|
2010-09-07 22:39:28 +00:00
|
|
|
mSinkIsValid = false;
|
2001-03-02 06:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsInputStreamTee::TeeSegment(const char *buf, uint32_t count)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
2010-09-07 22:39:28 +00:00
|
|
|
if (!mSink) return NS_OK; // nothing to do
|
|
|
|
if (mLock) { // asynchronous case
|
|
|
|
NS_ASSERTION(mEventTarget, "mEventTarget is null, mLock is not null.");
|
|
|
|
if (!SinkIsValid()) {
|
|
|
|
return NS_OK; // nothing to do
|
|
|
|
}
|
2010-02-23 18:13:18 +00:00
|
|
|
nsRefPtr<nsIRunnable> event =
|
2010-09-07 22:39:28 +00:00
|
|
|
new nsInputStreamTeeWriteEvent(buf, count, mSink, this);
|
2010-02-23 18:13:18 +00:00
|
|
|
NS_ENSURE_TRUE(event, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
LOG(("nsInputStreamTee::TeeSegment [%p] dispatching write %u bytes\n",
|
2010-09-07 22:39:28 +00:00
|
|
|
this, count));
|
2010-02-23 18:13:18 +00:00
|
|
|
return mEventTarget->Dispatch(event, NS_DISPATCH_NORMAL);
|
2010-09-07 22:39:28 +00:00
|
|
|
} else { // synchronous case
|
|
|
|
NS_ASSERTION(!mEventTarget, "mEventTarget is not null, mLock is null.");
|
|
|
|
nsresult rv;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t totalBytesWritten = 0;
|
2010-09-07 22:39:28 +00:00
|
|
|
while (count) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t bytesWritten = 0;
|
2010-09-07 22:39:28 +00:00
|
|
|
rv = mSink->Write(buf + totalBytesWritten, count, &bytesWritten);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// ok, this is not a fatal error... just drop our reference to mSink
|
|
|
|
// and continue on as if nothing happened.
|
|
|
|
NS_WARNING("Write failed (non-fatal)");
|
|
|
|
// catch possible misuse of the input stream tee
|
|
|
|
NS_ASSERTION(rv != NS_BASE_STREAM_WOULD_BLOCK, "sink must be a blocking stream");
|
|
|
|
mSink = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
totalBytesWritten += bytesWritten;
|
|
|
|
NS_ASSERTION(bytesWritten <= count, "wrote too much");
|
|
|
|
count -= bytesWritten;
|
2002-05-10 18:38:09 +00:00
|
|
|
}
|
2010-09-07 22:39:28 +00:00
|
|
|
return NS_OK;
|
2001-03-02 06:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsInputStreamTee::WriteSegmentFun(nsIInputStream *in, void *closure, const char *fromSegment,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t offset, uint32_t count, uint32_t *writeCount)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsInputStreamTee *tee = reinterpret_cast<nsInputStreamTee *>(closure);
|
2001-03-02 06:10:00 +00:00
|
|
|
|
|
|
|
nsresult rv = tee->mWriter(in, tee->mClosure, fromSegment, offset, count, writeCount);
|
2001-03-29 02:42:00 +00:00
|
|
|
if (NS_FAILED(rv) || (*writeCount == 0)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ASSERTION((NS_FAILED(rv) ? (*writeCount == 0) : true),
|
2001-03-29 02:42:00 +00:00
|
|
|
"writer returned an error with non-zero writeCount");
|
2001-03-02 06:10:00 +00:00
|
|
|
return rv;
|
2001-03-29 02:42:00 +00:00
|
|
|
}
|
2001-03-02 06:10:00 +00:00
|
|
|
|
|
|
|
return tee->TeeSegment(fromSegment, *writeCount);
|
|
|
|
}
|
|
|
|
|
2010-09-07 22:39:28 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsInputStreamTee,
|
|
|
|
nsIInputStreamTee,
|
|
|
|
nsIInputStream)
|
2001-03-02 06:10:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::Close()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsresult rv = mSource->Close();
|
|
|
|
mSource = 0;
|
|
|
|
mSink = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsInputStreamTee::Available(uint64_t *avail)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return mSource->Available(avail);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsInputStreamTee::Read(char *buf, uint32_t count, uint32_t *bytesRead)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
nsresult rv = mSource->Read(buf, count, bytesRead);
|
|
|
|
if (NS_FAILED(rv) || (*bytesRead == 0))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return TeeSegment(buf, *bytesRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::ReadSegments(nsWriteSegmentFun writer,
|
|
|
|
void *closure,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count,
|
|
|
|
uint32_t *bytesRead)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
mWriter = writer;
|
|
|
|
mClosure = closure;
|
|
|
|
|
|
|
|
return mSource->ReadSegments(WriteSegmentFun, this, count, bytesRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsInputStreamTee::IsNonBlocking(bool *result)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSource, NS_ERROR_NOT_INITIALIZED);
|
2002-03-12 00:59:06 +00:00
|
|
|
return mSource->IsNonBlocking(result);
|
2001-03-02 06:10:00 +00:00
|
|
|
}
|
|
|
|
|
2002-05-10 18:38:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::SetSource(nsIInputStream *source)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
2002-05-10 18:38:09 +00:00
|
|
|
mSource = source;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-02 06:10:00 +00:00
|
|
|
|
2002-05-10 18:38:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::GetSource(nsIInputStream **source)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*source = mSource);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::SetSink(nsIOutputStream *sink)
|
|
|
|
{
|
2003-10-09 01:54:07 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (sink) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool nonBlocking;
|
2003-10-09 01:54:07 +00:00
|
|
|
nsresult rv = sink->IsNonBlocking(&nonBlocking);
|
|
|
|
if (NS_FAILED(rv) || nonBlocking)
|
|
|
|
NS_ERROR("sink should be a blocking stream");
|
|
|
|
}
|
|
|
|
#endif
|
2001-03-02 06:10:00 +00:00
|
|
|
mSink = sink;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-05-10 18:38:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::GetSink(nsIOutputStream **sink)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*sink = mSink);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-23 18:13:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::SetEventTarget(nsIEventTarget *anEventTarget)
|
|
|
|
{
|
|
|
|
mEventTarget = anEventTarget;
|
2010-09-07 22:39:28 +00:00
|
|
|
if (mEventTarget) {
|
|
|
|
// Only need synchronization if this is an async tee
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
mLock = new Mutex("nsInputStreamTee.mLock");
|
2010-09-07 22:39:28 +00:00
|
|
|
}
|
2010-02-23 18:13:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-02 06:10:00 +00:00
|
|
|
|
2010-02-23 18:13:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::GetEventTarget(nsIEventTarget **anEventTarget)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*anEventTarget = mEventTarget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2010-02-23 18:13:18 +00:00
|
|
|
NS_NewInputStreamTeeAsync(nsIInputStream **result,
|
|
|
|
nsIInputStream *source,
|
|
|
|
nsIOutputStream *sink,
|
|
|
|
nsIEventTarget *anEventTarget)
|
2001-03-02 06:10:00 +00:00
|
|
|
{
|
2002-05-10 18:38:09 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2010-07-05 09:42:18 +00:00
|
|
|
nsCOMPtr<nsIInputStreamTee> tee = new nsInputStreamTee();
|
2001-03-02 06:10:00 +00:00
|
|
|
if (!tee)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2002-05-10 18:38:09 +00:00
|
|
|
rv = tee->SetSource(source);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = tee->SetSink(sink);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2010-02-23 18:13:18 +00:00
|
|
|
rv = tee->SetEventTarget(anEventTarget);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-05-10 18:38:09 +00:00
|
|
|
NS_ADDREF(*result = tee);
|
2001-03-02 06:10:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2010-02-23 18:13:18 +00:00
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2010-02-23 18:13:18 +00:00
|
|
|
NS_NewInputStreamTee(nsIInputStream **result,
|
|
|
|
nsIInputStream *source,
|
|
|
|
nsIOutputStream *sink)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return NS_NewInputStreamTeeAsync(result, source, sink, nullptr);
|
2010-02-23 18:13:18 +00:00
|
|
|
}
|