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/. */
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
#ifndef nsSocketTransport2_h__
|
|
|
|
#define nsSocketTransport2_h__
|
|
|
|
|
2004-06-10 02:40:02 +04:00
|
|
|
#ifdef DEBUG_darinf
|
|
|
|
#define ENABLE_SOCKET_TRACING
|
|
|
|
#endif
|
|
|
|
|
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"
|
2003-01-18 04:27:53 +03:00
|
|
|
#include "nsSocketTransportService2.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2015-01-30 18:55:07 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2003-01-18 04:27:53 +03:00
|
|
|
#include "nsISocketTransport.h"
|
|
|
|
#include "nsIAsyncInputStream.h"
|
|
|
|
#include "nsIAsyncOutputStream.h"
|
2005-04-06 05:33:28 +04:00
|
|
|
#include "nsIDNSListener.h"
|
2008-02-21 23:39:20 +03:00
|
|
|
#include "nsIClassInfo.h"
|
2012-12-24 01:08:43 +04:00
|
|
|
#include "mozilla/net/DNS.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "nsASocketHandler.h"
|
2015-07-07 12:13:00 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2013-03-03 12:04:38 +04:00
|
|
|
#include "prerror.h"
|
2014-04-16 07:00:39 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-03 12:04:38 +04:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
class nsSocketTransport;
|
2013-09-22 07:04:57 +04:00
|
|
|
class nsICancelable;
|
|
|
|
class nsIDNSRecord;
|
|
|
|
class nsIInterfaceRequestor;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2013-03-03 12:04:38 +04:00
|
|
|
nsresult
|
|
|
|
ErrorAccordingToNSPR(PRErrorCode errorCode);
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// after this short interval, we will return to PR_Poll
|
|
|
|
#define NS_SOCKET_CONNECT_TIMEOUT PR_MillisecondsToInterval(20)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsSocketInputStream : public nsIAsyncInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAM
|
|
|
|
|
2014-08-05 17:20:50 +04:00
|
|
|
explicit nsSocketInputStream(nsSocketTransport *);
|
2003-01-18 04:27:53 +03:00
|
|
|
virtual ~nsSocketInputStream();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsReferenced() { return mReaderRefCnt > 0; }
|
2003-01-18 04:27:53 +03:00
|
|
|
nsresult Condition() { return mCondition; }
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t ByteCount() { return mByteCount; }
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
// called by the socket transport on the socket thread...
|
|
|
|
void OnSocketReady(nsresult condition);
|
|
|
|
|
|
|
|
private:
|
2003-10-06 05:46:31 +04:00
|
|
|
nsSocketTransport *mTransport;
|
2013-07-19 06:24:13 +04:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mReaderRefCnt;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
// access to these is protected by mTransport->mLock
|
2003-10-06 05:46:31 +04:00
|
|
|
nsresult mCondition;
|
|
|
|
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCallbackFlags;
|
|
|
|
uint64_t mByteCount;
|
2003-01-18 04:27:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsSocketOutputStream : public nsIAsyncOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIOUTPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCOUTPUTSTREAM
|
|
|
|
|
2014-08-05 17:20:50 +04:00
|
|
|
explicit nsSocketOutputStream(nsSocketTransport *);
|
2003-01-18 04:27:53 +03:00
|
|
|
virtual ~nsSocketOutputStream();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsReferenced() { return mWriterRefCnt > 0; }
|
2003-01-18 04:27:53 +03:00
|
|
|
nsresult Condition() { return mCondition; }
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t ByteCount() { return mByteCount; }
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
// called by the socket transport on the socket thread...
|
|
|
|
void OnSocketReady(nsresult condition);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static NS_METHOD WriteFromSegments(nsIInputStream *, void *,
|
2012-08-22 19:56:38 +04:00
|
|
|
const char *, uint32_t offset,
|
|
|
|
uint32_t count, uint32_t *countRead);
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2003-10-06 05:46:31 +04:00
|
|
|
nsSocketTransport *mTransport;
|
2013-07-19 06:24:13 +04:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mWriterRefCnt;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
// access to these is protected by mTransport->mLock
|
2003-10-06 05:46:31 +04:00
|
|
|
nsresult mCondition;
|
|
|
|
nsCOMPtr<nsIOutputStreamCallback> mCallback;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCallbackFlags;
|
|
|
|
uint64_t mByteCount;
|
2003-01-18 04:27:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsSocketTransport final : public nsASocketHandler
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsISocketTransport
|
|
|
|
, public nsIDNSListener
|
|
|
|
, public nsIClassInfo
|
|
|
|
, public nsIInterfaceRequestor
|
2003-01-18 04:27:53 +03: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 08:29:02 +04:00
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-01-18 04:27:53 +03:00
|
|
|
NS_DECL_NSITRANSPORT
|
|
|
|
NS_DECL_NSISOCKETTRANSPORT
|
|
|
|
NS_DECL_NSIDNSLISTENER
|
2006-12-27 01:14:29 +03:00
|
|
|
NS_DECL_NSICLASSINFO
|
2015-01-30 18:55:07 +03:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
nsSocketTransport();
|
|
|
|
|
2003-11-15 03:13:59 +03:00
|
|
|
// this method instructs the socket transport to open a socket of the
|
|
|
|
// given type(s) to the given host or proxy.
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult Init(const char **socketTypes, uint32_t typeCount,
|
|
|
|
const nsACString &host, uint16_t port,
|
2015-04-09 18:31:59 +03:00
|
|
|
const nsACString &hostRoute, uint16_t portRoute,
|
2003-01-18 04:27:53 +03:00
|
|
|
nsIProxyInfo *proxyInfo);
|
|
|
|
|
2003-11-15 03:13:59 +03:00
|
|
|
// this method instructs the socket transport to use an already connected
|
|
|
|
// socket with the given address.
|
|
|
|
nsresult InitWithConnectedSocket(PRFileDesc *socketFD,
|
2012-12-24 01:08:43 +04:00
|
|
|
const mozilla::net::NetAddr *addr);
|
2003-11-15 03:13:59 +03:00
|
|
|
|
2014-09-19 19:25:00 +04:00
|
|
|
// this method instructs the socket transport to use an already connected
|
|
|
|
// socket with the given address, and additionally supplies security info.
|
|
|
|
nsresult InitWithConnectedSocket(PRFileDesc* aSocketFD,
|
|
|
|
const mozilla::net::NetAddr* aAddr,
|
|
|
|
nsISupports* aSecInfo);
|
|
|
|
|
2013-09-06 19:06:23 +04:00
|
|
|
// This method instructs the socket transport to open a socket
|
|
|
|
// connected to the given Unix domain address. We can only create
|
|
|
|
// unlayered, simple, stream sockets.
|
|
|
|
nsresult InitWithFilename(const char *filename);
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
// nsASocketHandler methods:
|
2015-03-21 19:28:04 +03:00
|
|
|
void OnSocketReady(PRFileDesc *, int16_t outFlags) override;
|
|
|
|
void OnSocketDetached(PRFileDesc *) override;
|
|
|
|
void IsLocal(bool *aIsLocal) override;
|
|
|
|
void OnKeepaliveEnabledPrefChange(bool aEnabled) override final;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2003-10-06 05:46:31 +04:00
|
|
|
// called when a socket event is handled
|
2012-08-22 19:56:38 +04:00
|
|
|
void OnSocketEvent(uint32_t type, nsresult status, nsISupports *param);
|
2003-10-06 05:46:31 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
uint64_t ByteCountReceived() override { return mInput.ByteCount(); }
|
|
|
|
uint64_t ByteCountSent() override { return mOutput.ByteCount(); }
|
2015-07-07 12:13:00 +03:00
|
|
|
static void CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled);
|
|
|
|
static void SendPRBlockingTelemetry(PRIntervalTime aStart,
|
|
|
|
mozilla::Telemetry::ID aIDNormal,
|
|
|
|
mozilla::Telemetry::ID aIDShutdown,
|
|
|
|
mozilla::Telemetry::ID aIDConnectivityChange,
|
|
|
|
mozilla::Telemetry::ID aIDLinkChange,
|
|
|
|
mozilla::Telemetry::ID aIDOffline);
|
2003-11-15 11:43:50 +03:00
|
|
|
protected:
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
virtual ~nsSocketTransport();
|
2014-04-16 17:52:43 +04:00
|
|
|
void CleanupTypes();
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2003-11-15 11:43:50 +03:00
|
|
|
private:
|
|
|
|
|
2003-10-06 05:46:31 +04:00
|
|
|
// event types
|
2003-01-18 04:27:53 +03:00
|
|
|
enum {
|
2003-10-06 05:46:31 +04:00
|
|
|
MSG_ENSURE_CONNECT,
|
|
|
|
MSG_DNS_LOOKUP_COMPLETE,
|
|
|
|
MSG_RETRY_INIT_SOCKET,
|
2005-02-01 18:22:20 +03:00
|
|
|
MSG_TIMEOUT_CHANGED,
|
2003-10-06 05:46:31 +04:00
|
|
|
MSG_INPUT_CLOSED,
|
|
|
|
MSG_INPUT_PENDING,
|
|
|
|
MSG_OUTPUT_CLOSED,
|
|
|
|
MSG_OUTPUT_PENDING
|
2003-01-18 04:27:53 +03:00
|
|
|
};
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult PostEvent(uint32_t type, nsresult status = NS_OK, nsISupports *param = nullptr);
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
enum {
|
|
|
|
STATE_CLOSED,
|
2016-01-28 23:17:57 +03:00
|
|
|
STATE_IDLE,
|
2003-01-18 04:27:53 +03:00
|
|
|
STATE_RESOLVING,
|
|
|
|
STATE_CONNECTING,
|
|
|
|
STATE_TRANSFERRING
|
|
|
|
};
|
|
|
|
|
2013-12-17 04:46:09 +04:00
|
|
|
// Safer way to get and automatically release PRFileDesc objects.
|
|
|
|
class MOZ_STACK_CLASS PRFileDescAutoLock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef mozilla::MutexAutoLock MutexAutoLock;
|
|
|
|
|
2014-08-05 17:20:50 +04:00
|
|
|
explicit PRFileDescAutoLock(nsSocketTransport *aSocketTransport,
|
|
|
|
nsresult *aConditionWhileLocked = nullptr)
|
2013-12-17 04:46:09 +04:00
|
|
|
: mSocketTransport(aSocketTransport)
|
|
|
|
, mFd(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSocketTransport);
|
|
|
|
MutexAutoLock lock(mSocketTransport->mLock);
|
|
|
|
if (aConditionWhileLocked) {
|
|
|
|
*aConditionWhileLocked = mSocketTransport->mCondition;
|
|
|
|
if (NS_FAILED(mSocketTransport->mCondition)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFd = mSocketTransport->GetFD_Locked();
|
|
|
|
}
|
|
|
|
~PRFileDescAutoLock() {
|
|
|
|
MutexAutoLock lock(mSocketTransport->mLock);
|
|
|
|
if (mFd) {
|
|
|
|
mSocketTransport->ReleaseFD_Locked(mFd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool IsInitialized() {
|
|
|
|
return mFd;
|
|
|
|
}
|
|
|
|
operator PRFileDesc*() {
|
|
|
|
return mFd;
|
|
|
|
}
|
2014-02-06 23:51:38 +04:00
|
|
|
nsresult SetKeepaliveEnabled(bool aEnable);
|
|
|
|
nsresult SetKeepaliveVals(bool aEnabled, int aIdleTime,
|
|
|
|
int aRetryInterval, int aProbeCount);
|
2013-12-17 04:46:09 +04:00
|
|
|
private:
|
|
|
|
operator PRFileDescAutoLock*() { return nullptr; }
|
2014-02-06 23:51:38 +04:00
|
|
|
|
2013-12-17 04:46:09 +04:00
|
|
|
// Weak ptr to nsSocketTransport since this is a stack class only.
|
|
|
|
nsSocketTransport *mSocketTransport;
|
|
|
|
PRFileDesc *mFd;
|
|
|
|
};
|
|
|
|
friend class PRFileDescAutoLock;
|
|
|
|
|
|
|
|
class LockedPRFileDesc
|
|
|
|
{
|
|
|
|
public:
|
2014-08-05 17:20:50 +04:00
|
|
|
explicit LockedPRFileDesc(nsSocketTransport *aSocketTransport)
|
2013-12-17 04:46:09 +04:00
|
|
|
: mSocketTransport(aSocketTransport)
|
|
|
|
, mFd(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSocketTransport);
|
|
|
|
}
|
|
|
|
~LockedPRFileDesc() {}
|
|
|
|
bool IsInitialized() {
|
|
|
|
return mFd;
|
|
|
|
}
|
|
|
|
LockedPRFileDesc& operator=(PRFileDesc *aFd) {
|
|
|
|
mSocketTransport->mLock.AssertCurrentThreadOwns();
|
|
|
|
mFd = aFd;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
operator PRFileDesc*() {
|
|
|
|
if (mSocketTransport->mAttached) {
|
|
|
|
mSocketTransport->mLock.AssertCurrentThreadOwns();
|
|
|
|
}
|
|
|
|
return mFd;
|
|
|
|
}
|
|
|
|
bool operator==(PRFileDesc *aFd) {
|
|
|
|
mSocketTransport->mLock.AssertCurrentThreadOwns();
|
|
|
|
return mFd == aFd;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
operator LockedPRFileDesc*() { return nullptr; }
|
|
|
|
// Weak ptr to nsSocketTransport since it owns this class.
|
|
|
|
nsSocketTransport *mSocketTransport;
|
|
|
|
PRFileDesc *mFd;
|
|
|
|
};
|
|
|
|
friend class LockedPRFileDesc;
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// these members are "set" at initialization time and are never modified
|
|
|
|
// afterwards. this allows them to be safely accessed from any thread.
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// socket type info:
|
2004-12-16 05:46:12 +03:00
|
|
|
char **mTypes;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mTypeCount;
|
2004-12-16 05:46:12 +03:00
|
|
|
nsCString mHost;
|
|
|
|
nsCString mProxyHost;
|
2015-04-09 18:31:59 +03:00
|
|
|
nsCString mOriginHost;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mPort;
|
2015-11-25 00:56:00 +03:00
|
|
|
nsCOMPtr<nsIProxyInfo> mProxyInfo;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mProxyPort;
|
2015-04-09 18:31:59 +03:00
|
|
|
uint16_t mOriginPort;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mProxyTransparent;
|
|
|
|
bool mProxyTransparentResolvesHost;
|
2014-04-16 17:52:43 +04:00
|
|
|
bool mHttpsProxy;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mConnectionFlags;
|
2008-11-04 19:05:46 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t SocketPort() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyPort : mPort; }
|
2003-01-18 04:27:53 +03:00
|
|
|
const nsCString &SocketHost() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyHost : mHost; }
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// members accessible only on the socket transport thread:
|
|
|
|
// (the exception being initialization/shutdown time)
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// socket state vars:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mState; // STATE_??? flags
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAttached;
|
|
|
|
bool mInputClosed;
|
|
|
|
bool mOutputClosed;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2015-01-28 06:21:37 +03:00
|
|
|
// The platform-specific network interface id that this socket
|
|
|
|
// associated with.
|
|
|
|
nsCString mNetworkInterfaceId;
|
|
|
|
|
2003-10-07 09:11:41 +04:00
|
|
|
// this flag is used to determine if the results of a host lookup arrive
|
|
|
|
// recursively or not. this flag is not protected by any lock.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mResolving;
|
2003-10-07 09:11:41 +04:00
|
|
|
|
2005-04-06 05:33:28 +04:00
|
|
|
nsCOMPtr<nsICancelable> mDNSRequest;
|
2003-09-12 00:32:33 +04:00
|
|
|
nsCOMPtr<nsIDNSRecord> mDNSRecord;
|
2012-01-27 01:04:54 +04:00
|
|
|
|
2016-01-15 20:16:01 +03:00
|
|
|
// mNetAddr/mSelfAddr is valid from GetPeerAddr()/GetSelfAddr() once we have
|
2012-01-27 01:04:54 +04:00
|
|
|
// reached STATE_TRANSFERRING. It must not change after that.
|
2016-01-15 20:16:01 +03:00
|
|
|
void SetSocketName(PRFileDesc *fd);
|
2012-12-24 01:08:43 +04:00
|
|
|
mozilla::net::NetAddr mNetAddr;
|
2016-01-15 20:16:01 +03:00
|
|
|
mozilla::net::NetAddr mSelfAddr; // getsockname()
|
|
|
|
mozilla::Atomic<bool, mozilla::Relaxed> mNetAddrIsSet;
|
|
|
|
mozilla::Atomic<bool, mozilla::Relaxed> mSelfAddrIsSet;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2014-10-07 13:24:57 +04:00
|
|
|
nsAutoPtr<mozilla::net::NetAddr> mBindAddr;
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
// socket methods (these can only be called on the socket thread):
|
|
|
|
|
|
|
|
void SendStatus(nsresult status);
|
|
|
|
nsresult ResolveHost();
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult BuildSocket(PRFileDesc *&, bool &, bool &);
|
2003-01-18 04:27:53 +03:00
|
|
|
nsresult InitiateSocket();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool RecoverFromError();
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
void OnMsgInputPending()
|
|
|
|
{
|
|
|
|
if (mState == STATE_TRANSFERRING)
|
|
|
|
mPollFlags |= (PR_POLL_READ | PR_POLL_EXCEPT);
|
|
|
|
}
|
|
|
|
void OnMsgOutputPending()
|
|
|
|
{
|
|
|
|
if (mState == STATE_TRANSFERRING)
|
|
|
|
mPollFlags |= (PR_POLL_WRITE | PR_POLL_EXCEPT);
|
|
|
|
}
|
|
|
|
void OnMsgInputClosed(nsresult reason);
|
|
|
|
void OnMsgOutputClosed(nsresult reason);
|
|
|
|
|
|
|
|
// called when the socket is connected
|
2003-01-24 08:32:06 +03:00
|
|
|
void OnSocketConnected();
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// socket input/output objects. these may be accessed on any thread with
|
|
|
|
// the exception of some specific methods (XXX).
|
|
|
|
|
2013-12-17 04:46:09 +04:00
|
|
|
Mutex mLock; // protects members in this section.
|
|
|
|
LockedPRFileDesc mFD;
|
|
|
|
nsrefcnt mFDref; // mFD is closed when mFDref goes to zero.
|
|
|
|
bool mFDconnected; // mFD is available to consumer when TRUE.
|
2003-01-18 04:27:53 +03:00
|
|
|
|
2014-04-16 07:00:39 +04:00
|
|
|
// A delete protector reference to gSocketTransportService held for lifetime
|
|
|
|
// of 'this'. Sometimes used interchangably with gSocketTransportService due
|
|
|
|
// to scoping.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSocketTransportService> mSocketTransportService;
|
2014-04-16 07:00:39 +04:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
|
|
|
nsCOMPtr<nsITransportEventSink> mEventSink;
|
|
|
|
nsCOMPtr<nsISupports> mSecInfo;
|
|
|
|
|
|
|
|
nsSocketInputStream mInput;
|
|
|
|
nsSocketOutputStream mOutput;
|
|
|
|
|
|
|
|
friend class nsSocketInputStream;
|
|
|
|
friend class nsSocketOutputStream;
|
|
|
|
|
2005-01-26 05:13:14 +03:00
|
|
|
// socket timeouts are not protected by any lock.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mTimeouts[2];
|
2005-01-26 05:13:14 +03:00
|
|
|
|
2010-06-03 06:25:01 +04:00
|
|
|
// QoS setting for socket
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mQoSBits;
|
2010-06-03 06:25:01 +04:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
//
|
|
|
|
// mFD access methods: called with mLock held.
|
|
|
|
//
|
|
|
|
PRFileDesc *GetFD_Locked();
|
|
|
|
void ReleaseFD_Locked(PRFileDesc *fd);
|
|
|
|
|
|
|
|
//
|
|
|
|
// stream state changes (called outside mLock):
|
|
|
|
//
|
|
|
|
void OnInputClosed(nsresult reason)
|
|
|
|
{
|
|
|
|
// no need to post an event if called on the socket thread
|
|
|
|
if (PR_GetCurrentThread() == gSocketThread)
|
|
|
|
OnMsgInputClosed(reason);
|
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_INPUT_CLOSED, reason);
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
void OnInputPending()
|
|
|
|
{
|
|
|
|
// no need to post an event if called on the socket thread
|
|
|
|
if (PR_GetCurrentThread() == gSocketThread)
|
|
|
|
OnMsgInputPending();
|
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_INPUT_PENDING);
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
void OnOutputClosed(nsresult reason)
|
|
|
|
{
|
|
|
|
// no need to post an event if called on the socket thread
|
|
|
|
if (PR_GetCurrentThread() == gSocketThread)
|
|
|
|
OnMsgOutputClosed(reason); // XXX need to not be inside lock!
|
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_OUTPUT_CLOSED, reason);
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
void OnOutputPending()
|
|
|
|
{
|
|
|
|
// no need to post an event if called on the socket thread
|
|
|
|
if (PR_GetCurrentThread() == gSocketThread)
|
|
|
|
OnMsgOutputPending();
|
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_OUTPUT_PENDING);
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
2004-06-10 02:40:02 +04:00
|
|
|
|
|
|
|
#ifdef ENABLE_SOCKET_TRACING
|
2012-08-22 19:56:38 +04:00
|
|
|
void TraceInBuf(const char *buf, int32_t n);
|
|
|
|
void TraceOutBuf(const char *buf, int32_t n);
|
2004-06-10 02:40:02 +04:00
|
|
|
#endif
|
2014-02-06 23:51:38 +04:00
|
|
|
|
|
|
|
// Reads prefs to get default keepalive config.
|
|
|
|
nsresult EnsureKeepaliveValsAreInitialized();
|
|
|
|
|
|
|
|
// Groups calls to fd.SetKeepaliveEnabled and fd.SetKeepaliveVals.
|
|
|
|
nsresult SetKeepaliveEnabledInternal(bool aEnable);
|
|
|
|
|
|
|
|
// True if keepalive has been enabled by the socket owner. Note: Keepalive
|
|
|
|
// must also be enabled globally for it to be enabled in TCP.
|
|
|
|
bool mKeepaliveEnabled;
|
|
|
|
|
|
|
|
// Keepalive config (support varies by platform).
|
|
|
|
int32_t mKeepaliveIdleTimeS;
|
|
|
|
int32_t mKeepaliveRetryIntervalS;
|
|
|
|
int32_t mKeepaliveProbeCount;
|
2003-01-18 04:27:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !nsSocketTransport_h__
|