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"
|
2017-05-04 13:14:04 +03:00
|
|
|
#include "TCPFastOpen.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
|
|
|
|
2013-09-22 07:04:57 +04:00
|
|
|
class nsICancelable;
|
|
|
|
class nsIDNSRecord;
|
|
|
|
class nsIInterfaceRequestor;
|
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)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
nsresult ErrorAccordingToNSPR(PRErrorCode errorCode);
|
|
|
|
|
|
|
|
class nsSocketTransport;
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
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 *);
|
2018-04-30 19:46:04 +03:00
|
|
|
virtual ~nsSocketInputStream() = default;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
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;
|
2016-05-19 05:02:57 +03:00
|
|
|
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 *);
|
2018-04-30 19:46:04 +03:00
|
|
|
virtual ~nsSocketOutputStream() = default;
|
2003-01-18 04:27:53 +03:00
|
|
|
|
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...
|
2017-01-12 19:38:48 +03:00
|
|
|
void OnSocketReady(nsresult condition);
|
2003-01-18 04:27:53 +03:00
|
|
|
|
|
|
|
private:
|
2016-08-12 10:36:22 +03:00
|
|
|
static nsresult WriteFromSegments(nsIInputStream *, void *, 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;
|
2016-05-19 05:02:57 +03:00
|
|
|
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
|
|
|
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
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
nsSocketTransport();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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, const NetAddr *addr);
|
2018-11-30 13:46:48 +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 NetAddr *aAddr,
|
|
|
|
nsISupports *aSecInfo);
|
|
|
|
|
2017-12-15 14:21:19 +03:00
|
|
|
#ifdef XP_UNIX
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-26 12:06:42 +03:00
|
|
|
// This method instructs the socket transport to open a socket
|
|
|
|
// connected to the given Unix domain address that includes abstract
|
|
|
|
// socket address. If using abstract socket address, first character of
|
|
|
|
// name parameter has to be \0.
|
|
|
|
// We can only create unlayered, simple, stream sockets.
|
|
|
|
nsresult InitWithName(const char *name, size_t len);
|
2017-12-15 14:21:19 +03:00
|
|
|
#endif
|
2013-09-06 19:06:23 +04:00
|
|
|
|
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;
|
2018-02-06 09:50:00 +03:00
|
|
|
void OnKeepaliveEnabledPrefChange(bool aEnabled) final;
|
2018-11-30 13:46:48 +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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
uint64_t ByteCountReceived() override { return mInput.ByteCount(); }
|
|
|
|
uint64_t ByteCountSent() override { return mOutput.ByteCount(); }
|
2017-11-27 23:12:31 +03:00
|
|
|
static void CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled);
|
2015-07-07 12:13:00 +03:00
|
|
|
static void SendPRBlockingTelemetry(
|
2017-02-15 22:15:15 +03:00
|
|
|
PRIntervalTime aStart, Telemetry::HistogramID aIDNormal,
|
|
|
|
Telemetry::HistogramID aIDShutdown,
|
|
|
|
Telemetry::HistogramID aIDConnectivityChange,
|
|
|
|
Telemetry::HistogramID aIDLinkChange, Telemetry::HistogramID aIDOffline);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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();
|
2018-11-30 13:46:48 +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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-12-17 04:46:09 +04:00
|
|
|
// Safer way to get and automatically release PRFileDesc objects.
|
|
|
|
class MOZ_STACK_CLASS PRFileDescAutoLock {
|
|
|
|
public:
|
2014-08-05 17:20:50 +04:00
|
|
|
explicit PRFileDescAutoLock(nsSocketTransport *aSocketTransport,
|
2017-05-04 13:14:04 +03:00
|
|
|
bool aAlsoDuringFastOpen,
|
2014-08-05 17:20:50 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aAlsoDuringFastOpen) {
|
|
|
|
mFd = mSocketTransport->GetFD_Locked();
|
|
|
|
} else {
|
|
|
|
mFd = mSocketTransport->GetFD_LockedAlsoDuringFastOpen();
|
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
~PRFileDescAutoLock() {
|
|
|
|
MutexAutoLock lock(mSocketTransport->mLock);
|
|
|
|
if (mFd) {
|
|
|
|
mSocketTransport->ReleaseFD_Locked(mFd);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
bool IsInitialized() { return mFd; }
|
2013-12-17 04:46:09 +04:00
|
|
|
operator PRFileDesc *() { return mFd; }
|
|
|
|
nsresult SetKeepaliveEnabled(bool aEnable);
|
|
|
|
nsresult SetKeepaliveVals(bool aEnabled, int aIdleTime, int aRetryInterval,
|
2017-05-04 13:14:04 +03:00
|
|
|
int aProbeCount);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-04 13:14:04 +03:00
|
|
|
private:
|
2014-04-16 07:00:39 +04:00
|
|
|
operator PRFileDescAutoLock *() { return nullptr; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-16 07:00:39 +04:00
|
|
|
// Weak ptr to nsSocketTransport since this is a stack class only.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsSocketTransport *mSocketTransport;
|
2003-01-18 04:27:53 +03:00
|
|
|
PRFileDesc *mFd;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2017-05-04 13:14:04 +03:00
|
|
|
friend class PRFileDescAutoLock;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
class LockedPRFileDesc {
|
|
|
|
public:
|
|
|
|
explicit LockedPRFileDesc(nsSocketTransport *aSocketTransport)
|
2017-04-27 21:34:42 +03:00
|
|
|
: mSocketTransport(aSocketTransport), mFd(nullptr) {
|
2003-10-06 05:46:31 +04:00
|
|
|
MOZ_ASSERT(aSocketTransport);
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
2018-04-30 19:46:04 +03:00
|
|
|
~LockedPRFileDesc() = default;
|
2003-01-18 04:27:53 +03:00
|
|
|
bool IsInitialized() { return mFd; }
|
|
|
|
LockedPRFileDesc &operator=(PRFileDesc *aFd) {
|
|
|
|
mSocketTransport->mLock.AssertCurrentThreadOwns();
|
|
|
|
mFd = aFd;
|
2017-04-27 21:34:42 +03:00
|
|
|
return *this;
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
operator PRFileDesc *() {
|
|
|
|
if (mSocketTransport->mAttached) {
|
|
|
|
mSocketTransport->mLock.AssertCurrentThreadOwns();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-10-06 05:46:31 +04:00
|
|
|
return mFd;
|
2003-01-18 04:27:53 +03:00
|
|
|
}
|
|
|
|
bool operator==(PRFileDesc *aFd) {
|
|
|
|
mSocketTransport->mLock.AssertCurrentThreadOwns();
|
|
|
|
return mFd == aFd;
|
|
|
|
}
|
2004-06-10 02:40:02 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2013-12-17 04:46:09 +04:00
|
|
|
operator LockedPRFileDesc *() { return nullptr; }
|
|
|
|
// Weak ptr to nsSocketTransport since it owns this class.
|
|
|
|
nsSocketTransport *mSocketTransport;
|
|
|
|
PRFileDesc *mFd;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2013-12-17 04:46:09 +04:00
|
|
|
friend class LockedPRFileDesc;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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.
|
|
|
|
//-------------------------------------------------------------------------
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
// 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;
|
2018-03-16 16:06:00 +03:00
|
|
|
// When we fail to connect using a prefered IP family, we tell the consumer to
|
|
|
|
// reset the IP family preference on the connection entry.
|
|
|
|
bool mResetFamilyPreference;
|
2017-08-16 22:41:16 +03:00
|
|
|
uint32_t mTlsFlags;
|
2016-12-22 10:38:06 +03:00
|
|
|
bool mReuseAddrPort;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-21 06:43:06 +03:00
|
|
|
// The origin attributes are used to create sockets. The first party domain
|
|
|
|
// will eventually be used to isolate OCSP cache and is only non-empty when
|
|
|
|
// "privacy.firstparty.isolate" is enabled. Setting this is the only way to
|
|
|
|
// carry origin attributes down to NSPR layers which are final consumers.
|
|
|
|
// It must be set before the socket transport is built.
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes mOriginAttributes;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t SocketPort() {
|
|
|
|
return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyPort : mPort;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
const nsCString &SocketHost() {
|
|
|
|
return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyHost : mHost;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// members accessible only on the socket transport thread:
|
|
|
|
// (the exception being initialization/shutdown time)
|
|
|
|
//-------------------------------------------------------------------------
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
// 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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-04-06 05:33:28 +04:00
|
|
|
nsCOMPtr<nsICancelable> mDNSRequest;
|
2003-09-12 00:32:33 +04:00
|
|
|
nsCOMPtr<nsIDNSRecord> mDNSRecord;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-22 23:54:11 +03:00
|
|
|
nsresult mDNSLookupStatus;
|
|
|
|
PRIntervalTime mDNSARequestFinished;
|
|
|
|
nsCOMPtr<nsICancelable> mDNSTxtRequest;
|
|
|
|
nsCString mDNSRecordTxt;
|
|
|
|
bool mEsniQueried;
|
|
|
|
bool mEsniUsed;
|
2018-11-30 13:46:48 +03: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);
|
2016-05-19 05:02:57 +03:00
|
|
|
NetAddr mNetAddr;
|
|
|
|
NetAddr mSelfAddr; // getsockname()
|
|
|
|
Atomic<bool, Relaxed> mNetAddrIsSet;
|
|
|
|
Atomic<bool, Relaxed> mSelfAddrIsSet;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
nsAutoPtr<NetAddr> mBindAddr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
// socket methods (these can only be called on the socket thread):
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
void SendStatus(nsresult status);
|
|
|
|
nsresult ResolveHost();
|
2017-01-12 19:38:48 +03: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();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnMsgInputPending() {
|
|
|
|
if (mState == STATE_TRANSFERRING)
|
|
|
|
mPollFlags |= (PR_POLL_READ | PR_POLL_EXCEPT);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnMsgOutputPending() {
|
|
|
|
if (mState == STATE_TRANSFERRING)
|
|
|
|
mPollFlags |= (PR_POLL_WRITE | PR_POLL_EXCEPT);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnMsgInputClosed(nsresult reason);
|
|
|
|
void OnMsgOutputClosed(nsresult reason);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
// called when the socket is connected
|
2003-01-24 08:32:06 +03:00
|
|
|
void OnSocketConnected();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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).
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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.
|
2017-05-04 13:14:04 +03:00
|
|
|
bool mFDFastOpenInProgress; // Fast Open is in progress, so
|
|
|
|
// socket available for some
|
|
|
|
// operations.
|
2018-11-30 13:46:48 +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.
|
2013-12-17 04:46:09 +04:00
|
|
|
RefPtr<nsSocketTransportService> mSocketTransportService;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
|
|
|
nsCOMPtr<nsITransportEventSink> mEventSink;
|
|
|
|
nsCOMPtr<nsISupports> mSecInfo;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
nsSocketInputStream mInput;
|
|
|
|
nsSocketOutputStream mOutput;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
friend class nsSocketInputStream;
|
|
|
|
friend class nsSocketOutputStream;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-01-09 14:48:23 +03:00
|
|
|
// linger options to use when closing
|
|
|
|
bool mLingerPolarity;
|
|
|
|
int16_t mLingerTimeout;
|
|
|
|
|
2010-06-03 06:25:01 +04:00
|
|
|
// QoS setting for socket
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mQoSBits;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
//
|
2003-01-18 04:27:53 +03:00
|
|
|
// mFD access methods: called with mLock held.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2016-01-15 20:16:01 +03:00
|
|
|
PRFileDesc *GetFD_Locked();
|
2017-05-04 13:14:04 +03:00
|
|
|
PRFileDesc *GetFD_LockedAlsoDuringFastOpen();
|
2016-01-15 20:16:01 +03:00
|
|
|
void ReleaseFD_Locked(PRFileDesc *fd);
|
2017-05-04 13:15:16 +03:00
|
|
|
bool FastOpenInProgress();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
//
|
2003-01-18 04:27:53 +03:00
|
|
|
// stream state changes (called outside mLock):
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnInputClosed(nsresult reason) {
|
|
|
|
// no need to post an event if called on the socket thread
|
2017-04-27 21:34:42 +03:00
|
|
|
if (OnSocketThread())
|
2003-01-18 04:27:53 +03:00
|
|
|
OnMsgInputClosed(reason);
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_INPUT_CLOSED, reason);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnInputPending() {
|
|
|
|
// no need to post an event if called on the socket thread
|
2017-04-27 21:34:42 +03:00
|
|
|
if (OnSocketThread())
|
2003-01-18 04:27:53 +03:00
|
|
|
OnMsgInputPending();
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_INPUT_PENDING);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnOutputClosed(nsresult reason) {
|
|
|
|
// no need to post an event if called on the socket thread
|
2017-04-27 21:34:42 +03:00
|
|
|
if (OnSocketThread())
|
2003-01-18 04:27:53 +03:00
|
|
|
OnMsgOutputClosed(reason); // XXX need to not be inside lock!
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_OUTPUT_CLOSED, reason);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-01-18 04:27:53 +03:00
|
|
|
void OnOutputPending() {
|
|
|
|
// no need to post an event if called on the socket thread
|
2017-04-27 21:34:42 +03:00
|
|
|
if (OnSocketThread())
|
2003-01-18 04:27:53 +03:00
|
|
|
OnMsgOutputPending();
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2003-10-06 05:46:31 +04:00
|
|
|
PostEvent(MSG_OUTPUT_PENDING);
|
2018-11-30 13:46:48 +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;
|
2017-05-04 13:14:04 +03:00
|
|
|
|
|
|
|
// A Fast Open callback.
|
|
|
|
TCPFastOpen *mFastOpenCallback;
|
2017-05-04 13:15:16 +03:00
|
|
|
bool mFastOpenLayerHasBufferedData;
|
2017-08-20 10:45:17 +03:00
|
|
|
uint8_t mFastOpenStatus;
|
2017-08-20 10:45:26 +03:00
|
|
|
nsresult mFirstRetryError;
|
2017-05-24 12:19:40 +03:00
|
|
|
|
|
|
|
bool mDoNotRetryToConnect;
|
2003-01-18 04:27:53 +03:00
|
|
|
};
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2003-01-18 04:27:53 +03:00
|
|
|
#endif // !nsSocketTransport_h__
|