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/. */
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
#ifndef nsSocketTransport2_h__
|
|
|
|
#define nsSocketTransport2_h__
|
|
|
|
|
2004-06-09 22:40:02 +00: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 04:29:02 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2003-01-18 01:27:53 +00:00
|
|
|
#include "nsSocketTransportService2.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsISocketTransport.h"
|
|
|
|
#include "nsIAsyncInputStream.h"
|
|
|
|
#include "nsIAsyncOutputStream.h"
|
2005-04-06 01:33:28 +00:00
|
|
|
#include "nsIDNSListener.h"
|
2008-02-21 20:39:20 +00:00
|
|
|
#include "nsIClassInfo.h"
|
2012-12-23 21:08:43 +00:00
|
|
|
#include "mozilla/net/DNS.h"
|
2013-09-22 03:04:57 +00:00
|
|
|
#include "nsASocketHandler.h"
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2013-03-03 08:04:38 +00:00
|
|
|
#include "prerror.h"
|
2014-04-16 03:00:39 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-03 08:04:38 +00:00
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
class nsSocketTransport;
|
2013-09-22 03:04:57 +00:00
|
|
|
class nsICancelable;
|
|
|
|
class nsIDNSRecord;
|
|
|
|
class nsIInterfaceRequestor;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2013-03-03 08:04:38 +00:00
|
|
|
nsresult
|
|
|
|
ErrorAccordingToNSPR(PRErrorCode errorCode);
|
|
|
|
|
2003-01-18 01:27:53 +00: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 13:20:50 +00:00
|
|
|
explicit nsSocketInputStream(nsSocketTransport *);
|
2003-01-18 01:27:53 +00:00
|
|
|
virtual ~nsSocketInputStream();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsReferenced() { return mReaderRefCnt > 0; }
|
2003-01-18 01:27:53 +00:00
|
|
|
nsresult Condition() { return mCondition; }
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t ByteCount() { return mByteCount; }
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
// called by the socket transport on the socket thread...
|
|
|
|
void OnSocketReady(nsresult condition);
|
|
|
|
|
|
|
|
private:
|
2003-10-06 01:46:31 +00:00
|
|
|
nsSocketTransport *mTransport;
|
2013-07-19 02:24:13 +00:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mReaderRefCnt;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
// access to these is protected by mTransport->mLock
|
2003-10-06 01:46:31 +00:00
|
|
|
nsresult mCondition;
|
|
|
|
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mCallbackFlags;
|
|
|
|
uint64_t mByteCount;
|
2003-01-18 01:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsSocketOutputStream : public nsIAsyncOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIOUTPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCOUTPUTSTREAM
|
|
|
|
|
2014-08-05 13:20:50 +00:00
|
|
|
explicit nsSocketOutputStream(nsSocketTransport *);
|
2003-01-18 01:27:53 +00:00
|
|
|
virtual ~nsSocketOutputStream();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsReferenced() { return mWriterRefCnt > 0; }
|
2003-01-18 01:27:53 +00:00
|
|
|
nsresult Condition() { return mCondition; }
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t ByteCount() { return mByteCount; }
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
// called by the socket transport on the socket thread...
|
|
|
|
void OnSocketReady(nsresult condition);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static NS_METHOD WriteFromSegments(nsIInputStream *, void *,
|
2012-08-22 15:56:38 +00:00
|
|
|
const char *, uint32_t offset,
|
|
|
|
uint32_t count, uint32_t *countRead);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
nsSocketTransport *mTransport;
|
2013-07-19 02:24:13 +00:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mWriterRefCnt;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
// access to these is protected by mTransport->mLock
|
2003-10-06 01:46:31 +00:00
|
|
|
nsresult mCondition;
|
|
|
|
nsCOMPtr<nsIOutputStreamCallback> mCallback;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mCallbackFlags;
|
|
|
|
uint64_t mByteCount;
|
2003-01-18 01:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-11-25 18:56:07 +00:00
|
|
|
class nsSocketTransport MOZ_FINAL : public nsASocketHandler
|
|
|
|
, public nsISocketTransport
|
|
|
|
, public nsIDNSListener
|
|
|
|
, public nsIClassInfo
|
2003-01-18 01:27:53 +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
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
public:
|
2013-07-19 02:24:13 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_DECL_NSITRANSPORT
|
|
|
|
NS_DECL_NSISOCKETTRANSPORT
|
|
|
|
NS_DECL_NSIDNSLISTENER
|
2006-12-26 22:14:29 +00:00
|
|
|
NS_DECL_NSICLASSINFO
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
nsSocketTransport();
|
|
|
|
|
2003-11-15 00:13:59 +00: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 15:56:38 +00:00
|
|
|
nsresult Init(const char **socketTypes, uint32_t typeCount,
|
|
|
|
const nsACString &host, uint16_t port,
|
2003-01-18 01:27:53 +00:00
|
|
|
nsIProxyInfo *proxyInfo);
|
|
|
|
|
2003-11-15 00:13:59 +00:00
|
|
|
// this method instructs the socket transport to use an already connected
|
|
|
|
// socket with the given address.
|
|
|
|
nsresult InitWithConnectedSocket(PRFileDesc *socketFD,
|
2012-12-23 21:08:43 +00:00
|
|
|
const mozilla::net::NetAddr *addr);
|
2003-11-15 00:13:59 +00:00
|
|
|
|
2014-09-19 15:25:00 +00: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 15:06:23 +00: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 01:27:53 +00:00
|
|
|
// nsASocketHandler methods:
|
2015-01-02 06:24:13 +00:00
|
|
|
void OnSocketReady(PRFileDesc *, int16_t outFlags) MOZ_OVERRIDE;
|
|
|
|
void OnSocketDetached(PRFileDesc *) MOZ_OVERRIDE;
|
|
|
|
void IsLocal(bool *aIsLocal) MOZ_OVERRIDE;
|
2014-02-06 19:51:38 +00:00
|
|
|
void OnKeepaliveEnabledPrefChange(bool aEnabled) MOZ_OVERRIDE MOZ_FINAL;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
// called when a socket event is handled
|
2012-08-22 15:56:38 +00:00
|
|
|
void OnSocketEvent(uint32_t type, nsresult status, nsISupports *param);
|
2003-10-06 01:46:31 +00:00
|
|
|
|
2015-01-02 06:24:13 +00:00
|
|
|
uint64_t ByteCountReceived() MOZ_OVERRIDE { return mInput.ByteCount(); }
|
|
|
|
uint64_t ByteCountSent() MOZ_OVERRIDE { return mOutput.ByteCount(); }
|
2003-11-15 08:43:50 +00:00
|
|
|
protected:
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
virtual ~nsSocketTransport();
|
2014-04-16 13:52:43 +00:00
|
|
|
void CleanupTypes();
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-11-15 08:43:50 +00:00
|
|
|
private:
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
// event types
|
2003-01-18 01:27:53 +00:00
|
|
|
enum {
|
2003-10-06 01:46:31 +00:00
|
|
|
MSG_ENSURE_CONNECT,
|
|
|
|
MSG_DNS_LOOKUP_COMPLETE,
|
|
|
|
MSG_RETRY_INIT_SOCKET,
|
2005-02-01 15:22:20 +00:00
|
|
|
MSG_TIMEOUT_CHANGED,
|
2003-10-06 01:46:31 +00:00
|
|
|
MSG_INPUT_CLOSED,
|
|
|
|
MSG_INPUT_PENDING,
|
|
|
|
MSG_OUTPUT_CLOSED,
|
|
|
|
MSG_OUTPUT_PENDING
|
2003-01-18 01:27:53 +00:00
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult PostEvent(uint32_t type, nsresult status = NS_OK, nsISupports *param = nullptr);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
STATE_CLOSED,
|
|
|
|
STATE_IDLE,
|
|
|
|
STATE_RESOLVING,
|
|
|
|
STATE_CONNECTING,
|
|
|
|
STATE_TRANSFERRING
|
|
|
|
};
|
|
|
|
|
2013-12-17 00:46:09 +00:00
|
|
|
// Safer way to get and automatically release PRFileDesc objects.
|
|
|
|
class MOZ_STACK_CLASS PRFileDescAutoLock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef mozilla::MutexAutoLock MutexAutoLock;
|
|
|
|
|
2014-08-05 13:20:50 +00:00
|
|
|
explicit PRFileDescAutoLock(nsSocketTransport *aSocketTransport,
|
|
|
|
nsresult *aConditionWhileLocked = nullptr)
|
2013-12-17 00:46:09 +00: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 19:51:38 +00:00
|
|
|
nsresult SetKeepaliveEnabled(bool aEnable);
|
|
|
|
nsresult SetKeepaliveVals(bool aEnabled, int aIdleTime,
|
|
|
|
int aRetryInterval, int aProbeCount);
|
2013-12-17 00:46:09 +00:00
|
|
|
private:
|
|
|
|
operator PRFileDescAutoLock*() { return nullptr; }
|
2014-02-06 19:51:38 +00:00
|
|
|
|
2013-12-17 00:46:09 +00: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 13:20:50 +00:00
|
|
|
explicit LockedPRFileDesc(nsSocketTransport *aSocketTransport)
|
2013-12-17 00:46:09 +00: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 01:27:53 +00: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 02:46:12 +00:00
|
|
|
char **mTypes;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mTypeCount;
|
2004-12-16 02:46:12 +00:00
|
|
|
nsCString mHost;
|
|
|
|
nsCString mProxyHost;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mPort;
|
|
|
|
uint16_t mProxyPort;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mProxyTransparent;
|
|
|
|
bool mProxyTransparentResolvesHost;
|
2014-04-16 13:52:43 +00:00
|
|
|
bool mHttpsProxy;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mConnectionFlags;
|
2008-11-04 16:05:46 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t SocketPort() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyPort : mPort; }
|
2003-01-18 01:27:53 +00: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 15:56:38 +00:00
|
|
|
uint32_t mState; // STATE_??? flags
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mAttached;
|
|
|
|
bool mInputClosed;
|
|
|
|
bool mOutputClosed;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-10-07 05:11:41 +00: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 06:19:26 +00:00
|
|
|
bool mResolving;
|
2003-10-07 05:11:41 +00:00
|
|
|
|
2005-04-06 01:33:28 +00:00
|
|
|
nsCOMPtr<nsICancelable> mDNSRequest;
|
2003-09-11 20:32:33 +00:00
|
|
|
nsCOMPtr<nsIDNSRecord> mDNSRecord;
|
2012-01-26 21:04:54 +00:00
|
|
|
|
|
|
|
// mNetAddr is valid from GetPeerAddr() once we have
|
|
|
|
// reached STATE_TRANSFERRING. It must not change after that.
|
2012-12-23 21:08:43 +00:00
|
|
|
mozilla::net::NetAddr mNetAddr;
|
2012-01-26 21:04:54 +00:00
|
|
|
bool mNetAddrIsSet;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2014-10-07 09:24:57 +00:00
|
|
|
nsAutoPtr<mozilla::net::NetAddr> mBindAddr;
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
// socket methods (these can only be called on the socket thread):
|
|
|
|
|
|
|
|
void SendStatus(nsresult status);
|
|
|
|
nsresult ResolveHost();
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult BuildSocket(PRFileDesc *&, bool &, bool &);
|
2003-01-18 01:27:53 +00:00
|
|
|
nsresult InitiateSocket();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool RecoverFromError();
|
2003-01-18 01:27:53 +00: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 05:32:06 +00:00
|
|
|
void OnSocketConnected();
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// socket input/output objects. these may be accessed on any thread with
|
|
|
|
// the exception of some specific methods (XXX).
|
|
|
|
|
2013-12-17 00:46:09 +00: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 01:27:53 +00:00
|
|
|
|
2014-04-16 03:00:39 +00:00
|
|
|
// A delete protector reference to gSocketTransportService held for lifetime
|
|
|
|
// of 'this'. Sometimes used interchangably with gSocketTransportService due
|
|
|
|
// to scoping.
|
|
|
|
nsRefPtr<nsSocketTransportService> mSocketTransportService;
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
|
|
|
nsCOMPtr<nsITransportEventSink> mEventSink;
|
|
|
|
nsCOMPtr<nsISupports> mSecInfo;
|
|
|
|
|
|
|
|
nsSocketInputStream mInput;
|
|
|
|
nsSocketOutputStream mOutput;
|
|
|
|
|
|
|
|
friend class nsSocketInputStream;
|
|
|
|
friend class nsSocketOutputStream;
|
|
|
|
|
2005-01-26 02:13:14 +00:00
|
|
|
// socket timeouts are not protected by any lock.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mTimeouts[2];
|
2005-01-26 02:13:14 +00:00
|
|
|
|
2010-06-03 02:25:01 +00:00
|
|
|
// QoS setting for socket
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mQoSBits;
|
2010-06-03 02:25:01 +00:00
|
|
|
|
2003-01-18 01:27:53 +00: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 01:46:31 +00:00
|
|
|
PostEvent(MSG_INPUT_CLOSED, reason);
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
void OnInputPending()
|
|
|
|
{
|
|
|
|
// no need to post an event if called on the socket thread
|
|
|
|
if (PR_GetCurrentThread() == gSocketThread)
|
|
|
|
OnMsgInputPending();
|
|
|
|
else
|
2003-10-06 01:46:31 +00:00
|
|
|
PostEvent(MSG_INPUT_PENDING);
|
2003-01-18 01:27:53 +00: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 01:46:31 +00:00
|
|
|
PostEvent(MSG_OUTPUT_CLOSED, reason);
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
void OnOutputPending()
|
|
|
|
{
|
|
|
|
// no need to post an event if called on the socket thread
|
|
|
|
if (PR_GetCurrentThread() == gSocketThread)
|
|
|
|
OnMsgOutputPending();
|
|
|
|
else
|
2003-10-06 01:46:31 +00:00
|
|
|
PostEvent(MSG_OUTPUT_PENDING);
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
2004-06-09 22:40:02 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_SOCKET_TRACING
|
2012-08-22 15:56:38 +00:00
|
|
|
void TraceInBuf(const char *buf, int32_t n);
|
|
|
|
void TraceOutBuf(const char *buf, int32_t n);
|
2004-06-09 22:40:02 +00:00
|
|
|
#endif
|
2014-02-06 19:51:38 +00: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 01:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !nsSocketTransport_h__
|