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