nsSocketTransport2.cpp (palemoon-29.4.1-source.tar.xz) | : | nsSocketTransport2.cpp (palemoon-29.4.2-source.tar.xz) | ||
---|---|---|---|---|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
/* vim:set ts=4 sw=4 et cindent: */ | ||||
/* This Source Code Form is subject to the terms of the Mozilla Public | /* 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 | * 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/. */ | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
#include "nsSocketTransport2.h" | #include "nsSocketTransport2.h" | |||
#include "mozilla/Attributes.h" | #include "mozilla/Attributes.h" | |||
#include "nsIOService.h" | #include "nsIOService.h" | |||
#include "nsStreamUtils.h" | #include "nsStreamUtils.h" | |||
#include "nsNetSegmentUtils.h" | #include "nsNetSegmentUtils.h" | |||
skipping to change at line 2102 | skipping to change at line 2101 | |||
NS_IMPL_CI_INTERFACE_GETTER(nsSocketTransport, | NS_IMPL_CI_INTERFACE_GETTER(nsSocketTransport, | |||
nsISocketTransport, | nsISocketTransport, | |||
nsITransport, | nsITransport, | |||
nsIDNSListener, | nsIDNSListener, | |||
nsIInterfaceRequestor) | nsIInterfaceRequestor) | |||
NS_IMETHODIMP | NS_IMETHODIMP | |||
nsSocketTransport::OpenInputStream(uint32_t flags, | nsSocketTransport::OpenInputStream(uint32_t flags, | |||
uint32_t segsize, | uint32_t segsize, | |||
uint32_t segcount, | uint32_t segcount, | |||
nsIInputStream **result) | nsIInputStream **aResult) | |||
{ | { | |||
SOCKET_LOG(("nsSocketTransport::OpenInputStream [this=%p flags=%x]\n", | SOCKET_LOG(("nsSocketTransport::OpenInputStream [this=%p flags=%x]\n", | |||
this, flags)); | this, flags)); | |||
NS_ENSURE_TRUE(!mInput.IsReferenced(), NS_ERROR_UNEXPECTED); | NS_ENSURE_TRUE(!mInput.IsReferenced(), NS_ERROR_UNEXPECTED); | |||
nsresult rv; | nsresult rv; | |||
nsCOMPtr<nsIAsyncInputStream> pipeIn; | nsCOMPtr<nsIAsyncInputStream> pipeIn; | |||
nsCOMPtr<nsIInputStream> result; | ||||
if (!(flags & OPEN_UNBUFFERED) || (flags & OPEN_BLOCKING)) { | if (!(flags & OPEN_UNBUFFERED) || (flags & OPEN_BLOCKING)) { | |||
// XXX if the caller wants blocking, then the caller also gets buffered! | // XXX if the caller wants blocking, then the caller also gets buffered! | |||
//bool openBuffered = !(flags & OPEN_UNBUFFERED); | //bool openBuffered = !(flags & OPEN_UNBUFFERED); | |||
bool openBlocking = (flags & OPEN_BLOCKING); | bool openBlocking = (flags & OPEN_BLOCKING); | |||
net_ResolveSegmentParams(segsize, segcount); | net_ResolveSegmentParams(segsize, segcount); | |||
// create a pipe | // create a pipe | |||
nsCOMPtr<nsIAsyncOutputStream> pipeOut; | nsCOMPtr<nsIAsyncOutputStream> pipeOut; | |||
rv = NS_NewPipe2(getter_AddRefs(pipeIn), getter_AddRefs(pipeOut), | rv = NS_NewPipe2(getter_AddRefs(pipeIn), getter_AddRefs(pipeOut), | |||
!openBlocking, true, segsize, segcount); | !openBlocking, true, segsize, segcount); | |||
if (NS_FAILED(rv)) return rv; | if (NS_FAILED(rv)) return rv; | |||
// async copy from socket to pipe | // async copy from socket to pipe | |||
rv = NS_AsyncCopy(&mInput, pipeOut, mSocketTransportService, | rv = NS_AsyncCopy(&mInput, pipeOut, mSocketTransportService, | |||
NS_ASYNCCOPY_VIA_WRITESEGMENTS, segsize); | NS_ASYNCCOPY_VIA_WRITESEGMENTS, segsize); | |||
if (NS_FAILED(rv)) return rv; | if (NS_FAILED(rv)) return rv; | |||
*result = pipeIn; | result = pipeIn; | |||
} | } | |||
else | else | |||
*result = &mInput; | result = &mInput; | |||
// flag input stream as open | // flag input stream as open | |||
mInputClosed = false; | mInputClosed = false; | |||
rv = PostEvent(MSG_ENSURE_CONNECT); | rv = PostEvent(MSG_ENSURE_CONNECT); | |||
if (NS_FAILED(rv)) return rv; | if (NS_FAILED(rv)) { | |||
return rv; | ||||
} | ||||
NS_ADDREF(*result); | result.forget(aResult); | |||
return NS_OK; | return NS_OK; | |||
} | } | |||
NS_IMETHODIMP | NS_IMETHODIMP | |||
nsSocketTransport::OpenOutputStream(uint32_t flags, | nsSocketTransport::OpenOutputStream(uint32_t flags, | |||
uint32_t segsize, | uint32_t segsize, | |||
uint32_t segcount, | uint32_t segcount, | |||
nsIOutputStream **result) | nsIOutputStream **aResult) | |||
{ | { | |||
SOCKET_LOG(("nsSocketTransport::OpenOutputStream [this=%p flags=%x]\n", | SOCKET_LOG(("nsSocketTransport::OpenOutputStream [this=%p flags=%x]\n", | |||
this, flags)); | this, flags)); | |||
NS_ENSURE_TRUE(!mOutput.IsReferenced(), NS_ERROR_UNEXPECTED); | NS_ENSURE_TRUE(!mOutput.IsReferenced(), NS_ERROR_UNEXPECTED); | |||
nsresult rv; | nsresult rv; | |||
nsCOMPtr<nsIAsyncOutputStream> pipeOut; | nsCOMPtr<nsIAsyncOutputStream> pipeOut; | |||
nsCOMPtr<nsIOutputStream> result; | ||||
if (!(flags & OPEN_UNBUFFERED) || (flags & OPEN_BLOCKING)) { | if (!(flags & OPEN_UNBUFFERED) || (flags & OPEN_BLOCKING)) { | |||
// XXX if the caller wants blocking, then the caller also gets buffered! | // XXX if the caller wants blocking, then the caller also gets buffered! | |||
//bool openBuffered = !(flags & OPEN_UNBUFFERED); | //bool openBuffered = !(flags & OPEN_UNBUFFERED); | |||
bool openBlocking = (flags & OPEN_BLOCKING); | bool openBlocking = (flags & OPEN_BLOCKING); | |||
net_ResolveSegmentParams(segsize, segcount); | net_ResolveSegmentParams(segsize, segcount); | |||
// create a pipe | // create a pipe | |||
nsCOMPtr<nsIAsyncInputStream> pipeIn; | nsCOMPtr<nsIAsyncInputStream> pipeIn; | |||
rv = NS_NewPipe2(getter_AddRefs(pipeIn), getter_AddRefs(pipeOut), | rv = NS_NewPipe2(getter_AddRefs(pipeIn), getter_AddRefs(pipeOut), | |||
true, !openBlocking, segsize, segcount); | true, !openBlocking, segsize, segcount); | |||
if (NS_FAILED(rv)) return rv; | if (NS_FAILED(rv)) return rv; | |||
// async copy from socket to pipe | // async copy from socket to pipe | |||
rv = NS_AsyncCopy(pipeIn, &mOutput, mSocketTransportService, | rv = NS_AsyncCopy(pipeIn, &mOutput, mSocketTransportService, | |||
NS_ASYNCCOPY_VIA_READSEGMENTS, segsize); | NS_ASYNCCOPY_VIA_READSEGMENTS, segsize); | |||
if (NS_FAILED(rv)) return rv; | if (NS_FAILED(rv)) return rv; | |||
*result = pipeOut; | result = pipeOut; | |||
} | } | |||
else | else | |||
*result = &mOutput; | result = &mOutput; | |||
// flag output stream as open | // flag output stream as open | |||
mOutputClosed = false; | mOutputClosed = false; | |||
rv = PostEvent(MSG_ENSURE_CONNECT); | rv = PostEvent(MSG_ENSURE_CONNECT); | |||
if (NS_FAILED(rv)) return rv; | if (NS_FAILED(rv)) return rv; | |||
NS_ADDREF(*result); | result.forget(aResult); | |||
return NS_OK; | return NS_OK; | |||
} | } | |||
NS_IMETHODIMP | NS_IMETHODIMP | |||
nsSocketTransport::Close(nsresult reason) | nsSocketTransport::Close(nsresult reason) | |||
{ | { | |||
if (NS_SUCCEEDED(reason)) | if (NS_SUCCEEDED(reason)) | |||
reason = NS_BASE_STREAM_CLOSED; | reason = NS_BASE_STREAM_CLOSED; | |||
mDoNotRetryToConnect = true; | mDoNotRetryToConnect = true; | |||
End of changes. 12 change blocks. | ||||
10 lines changed or deleted | 14 lines changed or added |