2014-05-05 21:30:43 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2010-02-23 21:13:18 +03: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 08:29:02 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2012-06-06 03:51:58 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2001-03-02 09:10:00 +03:00
|
|
|
#include "nsIInputStreamTee.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2010-02-23 21:13:18 +03: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 08:29:02 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2010-02-23 21:13:18 +03:00
|
|
|
|
2013-11-19 06:34:00 +04:00
|
|
|
#ifdef LOG
|
|
|
|
#undef LOG
|
|
|
|
#endif
|
2010-02-23 21:13:18 +03:00
|
|
|
#ifdef PR_LOGGING
|
2012-10-30 03:32:10 +04:00
|
|
|
static PRLogModuleInfo*
|
|
|
|
GetTeeLog()
|
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
static PRLogModuleInfo* sLog;
|
|
|
|
if (!sLog) {
|
2014-05-05 21:30:43 +04:00
|
|
|
sLog = PR_NewLogModule("nsInputStreamTee");
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
return sLog;
|
2012-10-30 03:32:10 +04:00
|
|
|
}
|
|
|
|
#define LOG(args) PR_LOG(GetTeeLog(), PR_LOG_DEBUG, args)
|
2010-02-23 21:13:18 +03:00
|
|
|
#else
|
|
|
|
#define LOG(args)
|
|
|
|
#endif
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsInputStreamTee final : public nsIInputStreamTee
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-05-05 21:30:43 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSIINPUTSTREAMTEE
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
nsInputStreamTee();
|
|
|
|
bool SinkIsValid();
|
|
|
|
void InvalidateSink();
|
2001-03-02 09:10:00 +03:00
|
|
|
|
|
|
|
private:
|
2014-05-15 00:15:46 +04:00
|
|
|
~nsInputStreamTee()
|
|
|
|
{
|
|
|
|
}
|
2004-01-15 09:14:18 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
nsresult TeeSegment(const char* aBuf, uint32_t aCount);
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
static NS_METHOD WriteSegmentFun(nsIInputStream*, void*, const char*,
|
|
|
|
uint32_t, uint32_t, uint32_t*);
|
2001-03-02 09:10:00 +03:00
|
|
|
|
|
|
|
private:
|
2014-05-05 21:30:43 +04:00
|
|
|
nsCOMPtr<nsIInputStream> mSource;
|
|
|
|
nsCOMPtr<nsIOutputStream> mSink;
|
|
|
|
nsCOMPtr<nsIEventTarget> mEventTarget;
|
|
|
|
nsWriteSegmentFun mWriter; // for implementing ReadSegments
|
2014-05-15 00:15:46 +04:00
|
|
|
void* mClosure; // for implementing ReadSegments
|
2014-05-05 21:30:43 +04:00
|
|
|
nsAutoPtr<Mutex> mLock; // synchronize access to mSinkIsValid
|
|
|
|
bool mSinkIsValid; // False if TeeWriteEvent fails
|
2001-03-02 09:10:00 +03:00
|
|
|
};
|
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
class nsInputStreamTeeWriteEvent : public nsRunnable
|
|
|
|
{
|
2010-02-23 21:13:18 +03:00
|
|
|
public:
|
2014-05-05 21:30:43 +04:00
|
|
|
// aTee's lock is held across construction of this object
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTeeWriteEvent(const char* aBuf, uint32_t aCount,
|
|
|
|
nsIOutputStream* aSink, nsInputStreamTee* aTee)
|
2014-05-05 21:30:43 +04:00
|
|
|
{
|
|
|
|
// copy the buffer - will be free'd by dtor
|
2014-05-15 00:15:46 +04:00
|
|
|
mBuf = (char*)malloc(aCount);
|
|
|
|
if (mBuf) {
|
|
|
|
memcpy(mBuf, (char*)aBuf, aCount);
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
mCount = aCount;
|
|
|
|
mSink = aSink;
|
|
|
|
bool isNonBlocking;
|
|
|
|
mSink->IsNonBlocking(&isNonBlocking);
|
|
|
|
NS_ASSERTION(isNonBlocking == false, "mSink is nonblocking");
|
|
|
|
mTee = aTee;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
if (!mBuf) {
|
|
|
|
NS_WARNING("nsInputStreamTeeWriteEvent::Run() "
|
|
|
|
"memory not allocated\n");
|
|
|
|
return NS_OK;
|
2010-02-23 21:13:18 +03:00
|
|
|
}
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mSink, "mSink is null!");
|
2010-02-23 21:13:18 +03:00
|
|
|
|
2014-05-05 21:30:43 +04: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 21:13:18 +03:00
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
LOG(("nsInputStreamTeeWriteEvent::Run() [%p]"
|
|
|
|
"will write %u bytes to %p\n",
|
|
|
|
this, mCount, mSink.get()));
|
|
|
|
|
|
|
|
uint32_t totalBytesWritten = 0;
|
|
|
|
while (mCount) {
|
|
|
|
nsresult rv;
|
|
|
|
uint32_t bytesWritten = 0;
|
|
|
|
rv = mSink->Write(mBuf + totalBytesWritten, mCount, &bytesWritten);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("nsInputStreamTeeWriteEvent::Run[%p] error %x in writing",
|
2014-05-15 00:15:46 +04:00
|
|
|
this, rv));
|
2014-05-05 21:30:43 +04:00
|
|
|
mTee->InvalidateSink();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
totalBytesWritten += bytesWritten;
|
|
|
|
NS_ASSERTION(bytesWritten <= mCount, "wrote too much");
|
|
|
|
mCount -= bytesWritten;
|
2010-02-23 21:13:18 +03:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsInputStreamTeeWriteEvent()
|
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (mBuf) {
|
|
|
|
free(mBuf);
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
mBuf = nullptr;
|
|
|
|
}
|
|
|
|
|
2010-02-23 21:13:18 +03:00
|
|
|
private:
|
2014-05-15 00:15:46 +04:00
|
|
|
char* mBuf;
|
2014-05-05 21:30:43 +04:00
|
|
|
uint32_t mCount;
|
|
|
|
nsCOMPtr<nsIOutputStream> mSink;
|
|
|
|
// back pointer to the tee that created this runnable
|
|
|
|
nsRefPtr<nsInputStreamTee> mTee;
|
2010-02-23 21:13:18 +03:00
|
|
|
};
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsInputStreamTee::nsInputStreamTee(): mLock(nullptr)
|
2014-05-15 00:15:46 +04:00
|
|
|
, mSinkIsValid(true)
|
2010-09-08 02:39:28 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsInputStreamTee::SinkIsValid()
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-05 21:30:43 +04:00
|
|
|
MutexAutoLock lock(*mLock);
|
|
|
|
return mSinkIsValid;
|
2010-09-08 02:39:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsInputStreamTee::InvalidateSink()
|
|
|
|
{
|
2014-05-05 21:30:43 +04:00
|
|
|
MutexAutoLock lock(*mLock);
|
|
|
|
mSinkIsValid = false;
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::TeeSegment(const char* aBuf, uint32_t aCount)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (!mSink) {
|
|
|
|
return NS_OK; // nothing to do
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
if (mLock) { // asynchronous case
|
|
|
|
NS_ASSERTION(mEventTarget, "mEventTarget is null, mLock is not null.");
|
|
|
|
if (!SinkIsValid()) {
|
|
|
|
return NS_OK; // nothing to do
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2014-05-15 00:15:46 +04:00
|
|
|
new nsInputStreamTeeWriteEvent(aBuf, aCount, mSink, this);
|
2014-05-05 21:30:43 +04:00
|
|
|
LOG(("nsInputStreamTee::TeeSegment [%p] dispatching write %u bytes\n",
|
2014-05-15 00:15:46 +04:00
|
|
|
this, aCount));
|
2014-05-05 21:30:43 +04:00
|
|
|
return mEventTarget->Dispatch(event, NS_DISPATCH_NORMAL);
|
|
|
|
} else { // synchronous case
|
|
|
|
NS_ASSERTION(!mEventTarget, "mEventTarget is not null, mLock is null.");
|
|
|
|
nsresult rv;
|
|
|
|
uint32_t totalBytesWritten = 0;
|
2014-05-15 00:15:46 +04:00
|
|
|
while (aCount) {
|
2014-05-05 21:30:43 +04:00
|
|
|
uint32_t bytesWritten = 0;
|
2014-05-15 00:15:46 +04:00
|
|
|
rv = mSink->Write(aBuf + totalBytesWritten, aCount, &bytesWritten);
|
2014-05-05 21:30:43 +04:00
|
|
|
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;
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_ASSERTION(bytesWritten <= aCount, "wrote too much");
|
|
|
|
aCount -= bytesWritten;
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::WriteSegmentFun(nsIInputStream* aIn, void* aClosure,
|
|
|
|
const char* aFromSegment, uint32_t aOffset,
|
|
|
|
uint32_t aCount, uint32_t* aWriteCount)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee* tee = reinterpret_cast<nsInputStreamTee*>(aClosure);
|
|
|
|
nsresult rv = tee->mWriter(aIn, tee->mClosure, aFromSegment, aOffset,
|
|
|
|
aCount, aWriteCount);
|
|
|
|
if (NS_FAILED(rv) || (*aWriteCount == 0)) {
|
|
|
|
NS_ASSERTION((NS_FAILED(rv) ? (*aWriteCount == 0) : true),
|
2014-05-05 21:30:43 +04:00
|
|
|
"writer returned an error with non-zero writeCount");
|
|
|
|
return rv;
|
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
return tee->TeeSegment(aFromSegment, *aWriteCount);
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsInputStreamTee,
|
|
|
|
nsIInputStreamTee,
|
|
|
|
nsIInputStream)
|
2001-03-02 09:10:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInputStreamTee::Close()
|
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSource)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
nsresult rv = mSource->Close();
|
|
|
|
mSource = 0;
|
|
|
|
mSink = 0;
|
|
|
|
return rv;
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::Available(uint64_t* aAvail)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSource)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
return mSource->Available(aAvail);
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::Read(char* aBuf, uint32_t aCount, uint32_t* aBytesRead)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSource)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
nsresult rv = mSource->Read(aBuf, aCount, aBytesRead);
|
|
|
|
if (NS_FAILED(rv) || (*aBytesRead == 0)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
return TeeSegment(aBuf, *aBytesRead);
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::ReadSegments(nsWriteSegmentFun aWriter,
|
|
|
|
void* aClosure,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* aBytesRead)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSource)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
mWriter = aWriter;
|
|
|
|
mClosure = aClosure;
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
return mSource->ReadSegments(WriteSegmentFun, this, aCount, aBytesRead);
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::IsNonBlocking(bool* aResult)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
if (NS_WARN_IF(!mSource)) {
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-05-15 00:15:46 +04:00
|
|
|
}
|
|
|
|
return mSource->IsNonBlocking(aResult);
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
2002-05-10 22:38:09 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::SetSource(nsIInputStream* aSource)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
mSource = aSource;
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
2002-05-10 22:38:09 +04:00
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2002-05-10 22:38:09 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::GetSource(nsIInputStream** aSource)
|
2002-05-10 22:38:09 +04:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_IF_ADDREF(*aSource = mSource);
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
2002-05-10 22:38:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::SetSink(nsIOutputStream* aSink)
|
2002-05-10 22:38:09 +04:00
|
|
|
{
|
2003-10-09 05:54:07 +04:00
|
|
|
#ifdef DEBUG
|
2014-05-15 00:15:46 +04:00
|
|
|
if (aSink) {
|
2014-05-05 21:30:43 +04:00
|
|
|
bool nonBlocking;
|
2014-05-15 00:15:46 +04:00
|
|
|
nsresult rv = aSink->IsNonBlocking(&nonBlocking);
|
|
|
|
if (NS_FAILED(rv) || nonBlocking) {
|
|
|
|
NS_ERROR("aSink should be a blocking stream");
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
}
|
2003-10-09 05:54:07 +04:00
|
|
|
#endif
|
2014-05-15 00:15:46 +04:00
|
|
|
mSink = aSink;
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
|
|
|
|
2002-05-10 22:38:09 +04:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::GetSink(nsIOutputStream** aSink)
|
2002-05-10 22:38:09 +04:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_IF_ADDREF(*aSink = mSink);
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
2002-05-10 22:38:09 +04:00
|
|
|
}
|
|
|
|
|
2010-02-23 21:13:18 +03:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::SetEventTarget(nsIEventTarget* aEventTarget)
|
2010-02-23 21:13:18 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
mEventTarget = aEventTarget;
|
2014-05-05 21:30:43 +04:00
|
|
|
if (mEventTarget) {
|
|
|
|
// Only need synchronization if this is an async tee
|
|
|
|
mLock = new Mutex("nsInputStreamTee.mLock");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2010-02-23 21:13:18 +03:00
|
|
|
}
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2010-02-23 21:13:18 +03:00
|
|
|
NS_IMETHODIMP
|
2014-05-15 00:15:46 +04:00
|
|
|
nsInputStreamTee::GetEventTarget(nsIEventTarget** aEventTarget)
|
2010-02-23 21:13:18 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_IF_ADDREF(*aEventTarget = mEventTarget);
|
2014-05-05 21:30:43 +04:00
|
|
|
return NS_OK;
|
2010-02-23 21:13:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
nsresult
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_NewInputStreamTeeAsync(nsIInputStream** aResult,
|
|
|
|
nsIInputStream* aSource,
|
|
|
|
nsIOutputStream* aSink,
|
|
|
|
nsIEventTarget* aEventTarget)
|
2001-03-02 09:10:00 +03:00
|
|
|
{
|
2014-05-05 21:30:43 +04:00
|
|
|
nsresult rv;
|
2001-03-02 09:10:00 +03:00
|
|
|
|
2014-05-05 21:30:43 +04:00
|
|
|
nsCOMPtr<nsIInputStreamTee> tee = new nsInputStreamTee();
|
2014-05-15 00:15:46 +04:00
|
|
|
rv = tee->SetSource(aSource);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-05-10 22:38:09 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
rv = tee->SetSink(aSink);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2010-02-23 21:13:18 +03:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
rv = tee->SetEventTarget(aEventTarget);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-05 21:30:43 +04:00
|
|
|
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_ADDREF(*aResult = tee);
|
2014-05-05 21:30:43 +04:00
|
|
|
return rv;
|
2001-03-02 09:10:00 +03:00
|
|
|
}
|
2010-02-23 21:13:18 +03:00
|
|
|
|
2011-08-18 17:46:39 +04:00
|
|
|
nsresult
|
2014-05-15 00:15:46 +04:00
|
|
|
NS_NewInputStreamTee(nsIInputStream** aResult,
|
|
|
|
nsIInputStream* aSource,
|
|
|
|
nsIOutputStream* aSink)
|
2010-02-23 21:13:18 +03:00
|
|
|
{
|
2014-05-15 00:15:46 +04:00
|
|
|
return NS_NewInputStreamTeeAsync(aResult, aSource, aSink, nullptr);
|
2010-02-23 21:13:18 +03:00
|
|
|
}
|
2013-11-21 01:01:59 +04:00
|
|
|
|
|
|
|
#undef LOG
|