2005-06-09 14:09:23 +00:00
|
|
|
// vim:set sw=4 sts=4 et cin:
|
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
|
|
|
|
2003-04-11 01:19:07 +00:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG
|
|
|
|
#endif
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
#include "nsSocketTransportService2.h"
|
|
|
|
#include "nsSocketTransport2.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2003-09-11 20:32:33 +00:00
|
|
|
#include "prnetdb.h"
|
2003-01-18 01:27:53 +00:00
|
|
|
#include "prerror.h"
|
|
|
|
#include "plstr.h"
|
2009-02-09 17:31:44 +00:00
|
|
|
#include "nsIPrefService.h"
|
2012-01-17 01:48:29 +00:00
|
|
|
#include "nsIPrefBranch.h"
|
2009-02-09 17:31:44 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2010-11-25 05:20:11 +00:00
|
|
|
#include "nsIOService.h"
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
// XXX: There is no good header file to put these in. :(
|
|
|
|
namespace mozilla { namespace psm {
|
|
|
|
|
|
|
|
void InitializeSSLServerCertVerificationThreads();
|
|
|
|
void StopSSLServerCertVerificationThreads();
|
|
|
|
|
|
|
|
} } // namespace mozilla::psm
|
|
|
|
|
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
|
|
|
using namespace mozilla;
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
#if defined(PR_LOGGING)
|
2012-07-30 14:20:58 +00:00
|
|
|
PRLogModuleInfo *gSocketTransportLog = nullptr;
|
2003-01-18 01:27:53 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsSocketTransportService *gSocketTransportService = nullptr;
|
|
|
|
PRThread *gSocketThread = nullptr;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2009-02-09 17:31:44 +00:00
|
|
|
#define SEND_BUFFER_PREF "network.tcp.sendbuffer"
|
2011-04-13 12:59:29 +00:00
|
|
|
#define SOCKET_LIMIT_TARGET 550U
|
|
|
|
#define SOCKET_LIMIT_MIN 50U
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t nsSocketTransportService::gMaxCount;
|
2011-04-13 12:59:29 +00:00
|
|
|
PRCallOnceType nsSocketTransportService::gMaxCountInitOnce;
|
2009-02-09 17:31:44 +00:00
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// ctor/dtor (called on the main/UI thread by the service manager)
|
|
|
|
|
|
|
|
nsSocketTransportService::nsSocketTransportService()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mThread(nullptr)
|
|
|
|
, mThreadEvent(nullptr)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mAutodialEnabled(false)
|
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
|
|
|
, mLock("nsSocketTransportService::mLock")
|
2011-10-17 14:59:28 +00:00
|
|
|
, mInitialized(false)
|
|
|
|
, mShuttingDown(false)
|
2012-09-17 23:45:10 +00:00
|
|
|
, mOffline(false)
|
|
|
|
, mGoingOffline(false)
|
2011-04-13 12:59:29 +00:00
|
|
|
, mActiveListSize(SOCKET_LIMIT_MIN)
|
|
|
|
, mIdleListSize(SOCKET_LIMIT_MIN)
|
2003-01-18 01:27:53 +00:00
|
|
|
, mActiveCount(0)
|
|
|
|
, mIdleCount(0)
|
2009-02-09 17:31:44 +00:00
|
|
|
, mSendBufferSize(0)
|
2011-10-25 15:36:49 +00:00
|
|
|
, mProbedMaxCount(false)
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
gSocketTransportLog = PR_NewLogModule("nsSocketTransport");
|
|
|
|
#endif
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
|
2003-10-06 01:46:31 +00:00
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
PR_CallOnce(&gMaxCountInitOnce, DiscoverMaxCount);
|
|
|
|
mActiveList = (SocketContext *)
|
|
|
|
moz_xmalloc(sizeof(SocketContext) * mActiveListSize);
|
|
|
|
mIdleList = (SocketContext *)
|
|
|
|
moz_xmalloc(sizeof(SocketContext) * mIdleListSize);
|
|
|
|
mPollList = (PRPollDesc *)
|
|
|
|
moz_xmalloc(sizeof(PRPollDesc) * (mActiveListSize + 1));
|
|
|
|
|
2003-10-09 01:54:07 +00:00
|
|
|
NS_ASSERTION(!gSocketTransportService, "must not instantiate twice");
|
2003-01-18 01:27:53 +00:00
|
|
|
gSocketTransportService = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSocketTransportService::~nsSocketTransportService()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_ASSERTION(!mInitialized, "not shutdown properly");
|
|
|
|
|
|
|
|
if (mThreadEvent)
|
|
|
|
PR_DestroyPollableEvent(mThreadEvent);
|
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
moz_free(mActiveList);
|
|
|
|
moz_free(mIdleList);
|
|
|
|
moz_free(mPollList);
|
2012-07-30 14:20:58 +00:00
|
|
|
gSocketTransportService = nullptr;
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// event queue (any thread)
|
|
|
|
|
2007-12-05 02:18:58 +00:00
|
|
|
already_AddRefed<nsIThread>
|
|
|
|
nsSocketTransportService::GetThreadSafely()
|
|
|
|
{
|
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
|
|
|
MutexAutoLock lock(mLock);
|
2007-12-05 02:18:58 +00:00
|
|
|
nsIThread* result = mThread;
|
|
|
|
NS_IF_ADDREF(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSocketTransportService::Dispatch(nsIRunnable *event, uint32_t flags)
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("STS dispatch [%p]\n", event));
|
2005-06-09 14:09:23 +00:00
|
|
|
|
2007-12-05 02:18:58 +00:00
|
|
|
nsCOMPtr<nsIThread> thread = GetThreadSafely();
|
|
|
|
NS_ENSURE_TRUE(thread, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
nsresult rv = thread->Dispatch(event, flags);
|
|
|
|
if (rv == NS_ERROR_UNEXPECTED) {
|
|
|
|
// Thread is no longer accepting events. We must have just shut it
|
|
|
|
// down on the main thread. Pretend we never saw it.
|
|
|
|
rv = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
return rv;
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
2003-10-06 01:46:31 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSocketTransportService::IsOnCurrentThread(bool *result)
|
2003-10-06 01:46:31 +00:00
|
|
|
{
|
2007-12-05 02:18:58 +00:00
|
|
|
nsCOMPtr<nsIThread> thread = GetThreadSafely();
|
|
|
|
NS_ENSURE_TRUE(thread, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return thread->IsOnCurrentThread(result);
|
2003-10-06 01:46:31 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// socket api (socket thread only)
|
|
|
|
|
2008-02-26 20:39:50 +00:00
|
|
|
NS_IMETHODIMP
|
2006-05-10 17:30:15 +00:00
|
|
|
nsSocketTransportService::NotifyWhenCanAttachSocket(nsIRunnable *event)
|
2003-04-08 22:18:10 +00:00
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::NotifyWhenCanAttachSocket\n"));
|
2003-04-08 22:18:10 +00:00
|
|
|
|
2003-10-09 01:54:07 +00:00
|
|
|
NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
|
|
|
|
|
2003-04-08 22:18:10 +00:00
|
|
|
if (CanAttachSocket()) {
|
2006-05-10 17:30:15 +00:00
|
|
|
return Dispatch(event, NS_DISPATCH_NORMAL);
|
2003-04-08 22:18:10 +00:00
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
mPendingSocketQ.PutEvent(event);
|
2003-04-08 22:18:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-26 20:39:50 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 01:27:53 +00:00
|
|
|
nsSocketTransportService::AttachSocket(PRFileDesc *fd, nsASocketHandler *handler)
|
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::AttachSocket [handler=%x]\n", handler));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-10-09 01:54:07 +00:00
|
|
|
NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
|
|
|
|
|
2008-02-26 20:39:50 +00:00
|
|
|
if (!CanAttachSocket()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2003-02-23 05:07:34 +00:00
|
|
|
SocketContext sock;
|
|
|
|
sock.mFD = fd;
|
|
|
|
sock.mHandler = handler;
|
2005-01-26 02:13:14 +00:00
|
|
|
sock.mElapsedTime = 0;
|
2003-02-23 05:07:34 +00:00
|
|
|
|
|
|
|
nsresult rv = AddToIdleList(&sock);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_ADDREF(handler);
|
|
|
|
return rv;
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-04-13 12:59:29 +00:00
|
|
|
nsSocketTransportService::DetachSocket(SocketContext *listHead, SocketContext *sock)
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::DetachSocket [handler=%x]\n", sock->mHandler));
|
2011-04-13 12:59:29 +00:00
|
|
|
NS_ABORT_IF_FALSE((listHead == mActiveList) || (listHead == mIdleList),
|
|
|
|
"DetachSocket invalid head");
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
// inform the handler that this socket is going away
|
|
|
|
sock->mHandler->OnSocketDetached(sock->mFD);
|
|
|
|
|
|
|
|
// cleanup
|
2012-07-30 14:20:58 +00:00
|
|
|
sock->mFD = nullptr;
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_RELEASE(sock->mHandler);
|
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
if (listHead == mActiveList)
|
2003-01-18 01:27:53 +00:00
|
|
|
RemoveFromPollList(sock);
|
|
|
|
else
|
|
|
|
RemoveFromIdleList(sock);
|
|
|
|
|
|
|
|
// NOTE: sock is now an invalid pointer
|
2003-04-08 22:18:10 +00:00
|
|
|
|
|
|
|
//
|
2003-10-06 01:46:31 +00:00
|
|
|
// notify the first element on the pending socket queue...
|
2003-04-08 22:18:10 +00:00
|
|
|
//
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIRunnable> event;
|
|
|
|
if (mPendingSocketQ.GetPendingEvent(getter_AddRefs(event))) {
|
|
|
|
// move event from pending queue to dispatch queue
|
|
|
|
return Dispatch(event, NS_DISPATCH_NORMAL);
|
2003-04-08 22:18:10 +00:00
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSocketTransportService::AddToPollList(SocketContext *sock)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_ABORT_IF_FALSE(!(((uint32_t)(sock - mActiveList)) < mActiveListSize),
|
2011-04-13 12:59:29 +00:00
|
|
|
"AddToPollList Socket Already Active");
|
2011-04-12 06:17:43 +00:00
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::AddToPollList [handler=%x]\n", sock->mHandler));
|
|
|
|
if (mActiveCount == mActiveListSize) {
|
|
|
|
SOCKET_LOG((" Active List size of %d met\n", mActiveCount));
|
|
|
|
if (!GrowActiveList()) {
|
|
|
|
NS_ERROR("too many active sockets");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2003-02-23 05:07:34 +00:00
|
|
|
}
|
2011-04-13 12:59:29 +00:00
|
|
|
|
2003-02-23 05:07:34 +00:00
|
|
|
mActiveList[mActiveCount] = *sock;
|
|
|
|
mActiveCount++;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
mPollList[mActiveCount].fd = sock->mFD;
|
|
|
|
mPollList[mActiveCount].in_flags = sock->mHandler->mPollFlags;
|
|
|
|
mPollList[mActiveCount].out_flags = 0;
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" active=%u idle=%u\n", mActiveCount, mIdleCount));
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSocketTransportService::RemoveFromPollList(SocketContext *sock)
|
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::RemoveFromPollList [handler=%x]\n", sock->mHandler));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t index = sock - mActiveList;
|
2011-04-13 12:59:29 +00:00
|
|
|
NS_ABORT_IF_FALSE(index < mActiveListSize, "invalid index");
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" index=%u mActiveCount=%u\n", index, mActiveCount));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-02-23 05:07:34 +00:00
|
|
|
if (index != mActiveCount-1) {
|
|
|
|
mActiveList[index] = mActiveList[mActiveCount-1];
|
|
|
|
mPollList[index+1] = mPollList[mActiveCount];
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
mActiveCount--;
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" active=%u idle=%u\n", mActiveCount, mIdleCount));
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSocketTransportService::AddToIdleList(SocketContext *sock)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_ABORT_IF_FALSE(!(((uint32_t)(sock - mIdleList)) < mIdleListSize),
|
2011-04-13 12:59:29 +00:00
|
|
|
"AddToIdlelList Socket Already Idle");
|
2011-04-12 06:17:43 +00:00
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::AddToIdleList [handler=%x]\n", sock->mHandler));
|
|
|
|
if (mIdleCount == mIdleListSize) {
|
|
|
|
SOCKET_LOG((" Idle List size of %d met\n", mIdleCount));
|
|
|
|
if (!GrowIdleList()) {
|
|
|
|
NS_ERROR("too many idle sockets");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2003-02-23 05:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mIdleList[mIdleCount] = *sock;
|
2003-01-18 01:27:53 +00:00
|
|
|
mIdleCount++;
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" active=%u idle=%u\n", mActiveCount, mIdleCount));
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSocketTransportService::RemoveFromIdleList(SocketContext *sock)
|
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::RemoveFromIdleList [handler=%x]\n", sock->mHandler));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t index = sock - mIdleList;
|
2011-04-13 12:59:29 +00:00
|
|
|
NS_ASSERTION(index < mIdleListSize, "invalid index in idle list");
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-02-23 05:07:34 +00:00
|
|
|
if (index != mIdleCount-1)
|
|
|
|
mIdleList[index] = mIdleList[mIdleCount-1];
|
2003-01-18 01:27:53 +00:00
|
|
|
mIdleCount--;
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" active=%u idle=%u\n", mActiveCount, mIdleCount));
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
2003-02-23 05:07:34 +00:00
|
|
|
void
|
|
|
|
nsSocketTransportService::MoveToIdleList(SocketContext *sock)
|
|
|
|
{
|
|
|
|
nsresult rv = AddToIdleList(sock);
|
|
|
|
if (NS_FAILED(rv))
|
2011-04-13 12:59:29 +00:00
|
|
|
DetachSocket(mActiveList, sock);
|
2003-02-23 05:07:34 +00:00
|
|
|
else
|
|
|
|
RemoveFromPollList(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSocketTransportService::MoveToPollList(SocketContext *sock)
|
|
|
|
{
|
|
|
|
nsresult rv = AddToPollList(sock);
|
|
|
|
if (NS_FAILED(rv))
|
2011-04-13 12:59:29 +00:00
|
|
|
DetachSocket(mIdleList, sock);
|
2003-02-23 05:07:34 +00:00
|
|
|
else
|
|
|
|
RemoveFromIdleList(sock);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-04-13 12:59:29 +00:00
|
|
|
nsSocketTransportService::GrowActiveList()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t toAdd = gMaxCount - mActiveListSize;
|
2011-04-13 12:59:29 +00:00
|
|
|
if (toAdd > 100)
|
|
|
|
toAdd = 100;
|
|
|
|
if (toAdd < 1)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-04-13 12:59:29 +00:00
|
|
|
|
|
|
|
mActiveListSize += toAdd;
|
|
|
|
mActiveList = (SocketContext *)
|
|
|
|
moz_xrealloc(mActiveList, sizeof(SocketContext) * mActiveListSize);
|
|
|
|
mPollList = (PRPollDesc *)
|
|
|
|
moz_xrealloc(mPollList, sizeof(PRPollDesc) * (mActiveListSize + 1));
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-04-13 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-04-13 12:59:29 +00:00
|
|
|
nsSocketTransportService::GrowIdleList()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t toAdd = gMaxCount - mIdleListSize;
|
2011-04-13 12:59:29 +00:00
|
|
|
if (toAdd > 100)
|
|
|
|
toAdd = 100;
|
|
|
|
if (toAdd < 1)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-04-13 12:59:29 +00:00
|
|
|
|
|
|
|
mIdleListSize += toAdd;
|
|
|
|
mIdleList = (SocketContext *)
|
|
|
|
moz_xrealloc(mIdleList, sizeof(SocketContext) * mIdleListSize);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-04-13 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
2005-01-26 02:13:14 +00:00
|
|
|
PRIntervalTime
|
|
|
|
nsSocketTransportService::PollTimeout()
|
|
|
|
{
|
|
|
|
if (mActiveCount == 0)
|
|
|
|
return NS_SOCKET_POLL_TIMEOUT;
|
|
|
|
|
|
|
|
// compute minimum time before any socket timeout expires.
|
2012-09-28 06:57:33 +00:00
|
|
|
uint32_t minR = UINT16_MAX;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i=0; i<mActiveCount; ++i) {
|
2005-01-26 02:13:14 +00:00
|
|
|
const SocketContext &s = mActiveList[i];
|
2005-02-01 15:22:20 +00:00
|
|
|
// mPollTimeout could be less than mElapsedTime if setTimeout
|
|
|
|
// was called with a value smaller than mElapsedTime.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t r = (s.mElapsedTime < s.mHandler->mPollTimeout)
|
2005-02-01 15:22:20 +00:00
|
|
|
? s.mHandler->mPollTimeout - s.mElapsedTime
|
|
|
|
: 0;
|
2005-01-26 02:13:14 +00:00
|
|
|
if (r < minR)
|
|
|
|
minR = r;
|
|
|
|
}
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("poll timeout: %lu\n", minR));
|
2005-01-26 02:13:14 +00:00
|
|
|
return PR_SecondsToInterval(minR);
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
|
|
|
nsSocketTransportService::Poll(bool wait, uint32_t *interval)
|
2003-02-06 21:20:26 +00:00
|
|
|
{
|
|
|
|
PRPollDesc *pollList;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t pollCount;
|
2003-02-06 21:20:26 +00:00
|
|
|
PRIntervalTime pollTimeout;
|
|
|
|
|
|
|
|
if (mPollList[0].fd) {
|
2003-02-23 05:07:34 +00:00
|
|
|
mPollList[0].out_flags = 0;
|
2003-02-06 21:20:26 +00:00
|
|
|
pollList = mPollList;
|
2003-02-23 05:07:34 +00:00
|
|
|
pollCount = mActiveCount + 1;
|
2005-01-26 02:13:14 +00:00
|
|
|
pollTimeout = PollTimeout();
|
2003-02-06 21:20:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// no pollable event, so busy wait...
|
2003-02-23 05:07:34 +00:00
|
|
|
pollCount = mActiveCount;
|
2003-02-06 21:20:26 +00:00
|
|
|
if (pollCount)
|
|
|
|
pollList = &mPollList[1];
|
|
|
|
else
|
2012-07-30 14:20:58 +00:00
|
|
|
pollList = nullptr;
|
2003-02-06 21:20:26 +00:00
|
|
|
pollTimeout = PR_MillisecondsToInterval(25);
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
if (!wait)
|
|
|
|
pollTimeout = PR_INTERVAL_NO_WAIT;
|
|
|
|
|
2005-01-26 02:13:14 +00:00
|
|
|
PRIntervalTime ts = PR_IntervalNow();
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" timeout = %i milliseconds\n",
|
2006-08-15 18:22:24 +00:00
|
|
|
PR_IntervalToMilliseconds(pollTimeout)));
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rv = PR_Poll(pollList, pollCount, pollTimeout);
|
2005-01-26 02:13:14 +00:00
|
|
|
|
2006-08-15 18:22:24 +00:00
|
|
|
PRIntervalTime passedInterval = PR_IntervalNow() - ts;
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" ...returned after %i milliseconds\n",
|
2006-08-15 18:22:24 +00:00
|
|
|
PR_IntervalToMilliseconds(passedInterval)));
|
|
|
|
|
|
|
|
*interval = PR_IntervalToSeconds(passedInterval);
|
2005-01-26 02:13:14 +00:00
|
|
|
return rv;
|
2003-02-06 21:20:26 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 20:39:20 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// xpcom api
|
|
|
|
|
2009-02-09 17:31:44 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS6(nsSocketTransportService,
|
2008-02-21 20:39:20 +00:00
|
|
|
nsISocketTransportService,
|
|
|
|
nsIEventTarget,
|
|
|
|
nsIThreadObserver,
|
|
|
|
nsIRunnable,
|
2009-02-09 17:31:44 +00:00
|
|
|
nsPISocketTransportService,
|
|
|
|
nsIObserver)
|
2008-02-21 20:39:20 +00:00
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
// called from main thread only
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::Init()
|
|
|
|
{
|
2006-05-10 17:30:15 +00:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_ERROR("wrong thread");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
if (mInitialized)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 19:33:57 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2003-01-31 01:51:45 +00:00
|
|
|
if (!mThreadEvent) {
|
2003-01-18 01:27:53 +00:00
|
|
|
mThreadEvent = PR_NewPollableEvent();
|
2003-02-06 21:20:26 +00:00
|
|
|
//
|
2003-01-31 01:51:45 +00:00
|
|
|
// NOTE: per bug 190000, this failure could be caused by Zone-Alarm
|
2003-02-06 21:20:26 +00:00
|
|
|
// or similar software.
|
|
|
|
//
|
|
|
|
// NOTE: per bug 191739, this failure could also be caused by lack
|
|
|
|
// of a loopback device on Windows and OS/2 platforms (NSPR creates
|
|
|
|
// a loopback socket pair on these platforms to implement a pollable
|
|
|
|
// event object). if we can't create a pollable event, then we'll
|
|
|
|
// have to "busy wait" to implement the socket event queue :-(
|
|
|
|
//
|
2006-08-24 18:46:59 +00:00
|
|
|
if (!mThreadEvent) {
|
|
|
|
NS_WARNING("running socket transport thread without a pollable event");
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("running socket transport thread without a pollable event"));
|
2006-08-24 18:46:59 +00:00
|
|
|
}
|
2003-01-31 01:51:45 +00:00
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2007-12-05 02:18:58 +00:00
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsresult rv = NS_NewThread(getter_AddRefs(thread), this);
|
2003-01-18 01:27:53 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2007-12-05 02:18:58 +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
|
|
|
MutexAutoLock lock(mLock);
|
2007-12-05 02:18:58 +00:00
|
|
|
// Install our mThread, protecting against concurrent readers
|
|
|
|
thread.swap(mThread);
|
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2012-01-17 01:48:29 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2012-09-28 12:14:26 +00:00
|
|
|
if (tmpPrefService)
|
2011-10-17 14:59:28 +00:00
|
|
|
tmpPrefService->AddObserver(SEND_BUFFER_PREF, this, false);
|
2009-02-09 17:31:44 +00:00
|
|
|
UpdatePrefs();
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// called from main thread only
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::Shutdown()
|
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("nsSocketTransportService::Shutdown\n"));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ENSURE_STATE(NS_IsMainThread());
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
if (!mInitialized)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 19:33:57 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
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
|
|
|
MutexAutoLock lock(mLock);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// signal the socket thread to shutdown
|
2011-10-17 14:59:28 +00:00
|
|
|
mShuttingDown = true;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2003-02-06 21:20:26 +00:00
|
|
|
if (mThreadEvent)
|
|
|
|
PR_SetPollableEvent(mThreadEvent);
|
|
|
|
// else wait for Poll timeout
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// join with thread
|
2006-05-10 17:30:15 +00:00
|
|
|
mThread->Shutdown();
|
2007-12-05 02:18:58 +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
|
|
|
MutexAutoLock lock(mLock);
|
2007-12-05 02:18:58 +00:00
|
|
|
// Drop our reference to mThread and make sure that any concurrent
|
|
|
|
// readers are excluded
|
2012-07-30 14:20:58 +00:00
|
|
|
mThread = nullptr;
|
2007-12-05 02:18:58 +00:00
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2012-01-17 01:48:29 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2009-02-09 17:31:44 +00:00
|
|
|
if (tmpPrefService)
|
|
|
|
tmpPrefService->RemoveObserver(SEND_BUFFER_PREF, this);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = false;
|
|
|
|
mShuttingDown = false;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 23:45:10 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::GetOffline(bool *offline)
|
|
|
|
{
|
|
|
|
*offline = mOffline;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::SetOffline(bool offline)
|
|
|
|
{
|
|
|
|
if (!mOffline && offline) {
|
|
|
|
// signal the socket thread to go offline, so it will detach sockets
|
|
|
|
mGoingOffline = true;
|
|
|
|
mOffline = true;
|
|
|
|
}
|
|
|
|
else if (mOffline && !offline) {
|
|
|
|
mOffline = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::CreateTransport(const char **types,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t typeCount,
|
2003-01-18 01:27:53 +00:00
|
|
|
const nsACString &host,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port,
|
2003-01-18 01:27:53 +00:00
|
|
|
nsIProxyInfo *proxyInfo,
|
|
|
|
nsISocketTransport **result)
|
|
|
|
{
|
2012-09-17 23:45:10 +00:00
|
|
|
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_ENSURE_TRUE(port >= 0 && port <= 0xFFFF, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
|
|
|
nsSocketTransport *trans = new nsSocketTransport();
|
|
|
|
if (!trans)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(trans);
|
|
|
|
|
|
|
|
nsresult rv = trans->Init(types, typeCount, host, port, proxyInfo);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(trans);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = trans;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSocketTransportService::GetAutodialEnabled(bool *value)
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
2003-01-22 00:09:05 +00:00
|
|
|
*value = mAutodialEnabled;
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSocketTransportService::SetAutodialEnabled(bool value)
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
2003-01-22 00:09:05 +00:00
|
|
|
mAutodialEnabled = value;
|
2003-01-18 01:27:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::OnDispatchedEvent(nsIThreadInternal *thread)
|
|
|
|
{
|
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
|
|
|
MutexAutoLock lock(mLock);
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mThreadEvent)
|
|
|
|
PR_SetPollableEvent(mThreadEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::OnProcessNextEvent(nsIThreadInternal *thread,
|
2012-08-22 15:56:38 +00:00
|
|
|
bool mayWait, uint32_t depth)
|
2006-05-10 17:30:15 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-07 00:06:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::AfterProcessNextEvent(nsIThreadInternal* thread,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t depth)
|
2006-06-07 00:06:11 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::Run()
|
|
|
|
{
|
2012-06-12 17:06:20 +00:00
|
|
|
PR_SetCurrentThreadName("Socket Thread");
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("STS thread init\n"));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
psm::InitializeSSLServerCertVerificationThreads();
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
gSocketThread = PR_GetCurrentThread();
|
|
|
|
|
2003-02-23 05:07:34 +00:00
|
|
|
// add thread event to poll list (mThreadEvent may be NULL)
|
|
|
|
mPollList[0].fd = mThreadEvent;
|
|
|
|
mPollList[0].in_flags = PR_POLL_READ;
|
2007-05-30 17:30:39 +00:00
|
|
|
mPollList[0].out_flags = 0;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsIThread *thread = NS_GetCurrentThread();
|
|
|
|
|
|
|
|
// hook ourselves up to observe event processing for this thread
|
|
|
|
nsCOMPtr<nsIThreadInternal> threadInt = do_QueryInterface(thread);
|
|
|
|
threadInt->SetObserver(this);
|
|
|
|
|
2012-02-27 15:32:09 +00:00
|
|
|
// make sure the pseudo random number generator is seeded on this thread
|
|
|
|
srand(PR_Now());
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
for (;;) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool pendingEvents = false;
|
2011-06-15 14:24:56 +00:00
|
|
|
thread->HasPendingEvents(&pendingEvents);
|
|
|
|
|
|
|
|
do {
|
|
|
|
// If there are pending events for this thread then
|
|
|
|
// DoPollIteration() should service the network without blocking.
|
|
|
|
DoPollIteration(!pendingEvents);
|
|
|
|
|
|
|
|
// If nothing was pending before the poll, it might be now
|
|
|
|
if (!pendingEvents)
|
|
|
|
thread->HasPendingEvents(&pendingEvents);
|
|
|
|
|
|
|
|
if (pendingEvents) {
|
|
|
|
NS_ProcessNextEvent(thread);
|
2011-10-17 14:59:28 +00:00
|
|
|
pendingEvents = false;
|
2011-06-15 14:24:56 +00:00
|
|
|
thread->HasPendingEvents(&pendingEvents);
|
|
|
|
}
|
|
|
|
} while (pendingEvents);
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2012-09-17 23:45:10 +00:00
|
|
|
bool goingOffline = false;
|
2006-05-10 17:30:15 +00:00
|
|
|
// now that our event queue is empty, check to see if we should exit
|
|
|
|
{
|
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
|
|
|
MutexAutoLock lock(mLock);
|
2006-05-10 17:30:15 +00:00
|
|
|
if (mShuttingDown)
|
|
|
|
break;
|
2012-09-17 23:45:10 +00:00
|
|
|
if (mGoingOffline) {
|
|
|
|
mGoingOffline = false;
|
|
|
|
goingOffline = true;
|
|
|
|
}
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
2012-09-17 23:45:10 +00:00
|
|
|
// Avoid potential deadlock
|
|
|
|
if (goingOffline)
|
|
|
|
Reset(true);
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("STS shutting down thread\n"));
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2012-09-17 23:45:10 +00:00
|
|
|
// detach all sockets, including locals
|
|
|
|
Reset(false);
|
2006-05-10 17:30:15 +00:00
|
|
|
|
|
|
|
// Final pass over the event queue. This makes sure that events posted by
|
|
|
|
// socket detach handlers get processed.
|
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gSocketThread = nullptr;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2011-12-01 22:37:57 +00:00
|
|
|
psm::StopSSLServerCertVerificationThreads();
|
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("STS thread exit\n"));
|
2006-05-10 17:30:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 23:45:10 +00:00
|
|
|
void
|
|
|
|
nsSocketTransportService::Reset(bool aGuardLocals)
|
|
|
|
{
|
|
|
|
// detach any sockets
|
|
|
|
int32_t i;
|
|
|
|
bool isGuarded;
|
|
|
|
for (i = mActiveCount - 1; i >= 0; --i) {
|
|
|
|
isGuarded = false;
|
|
|
|
if (aGuardLocals)
|
|
|
|
mActiveList[i].mHandler->IsLocal(&isGuarded);
|
|
|
|
if (!isGuarded)
|
|
|
|
DetachSocket(mActiveList, &mActiveList[i]);
|
|
|
|
}
|
|
|
|
for (i = mIdleCount - 1; i >= 0; --i) {
|
|
|
|
isGuarded = false;
|
|
|
|
if (aGuardLocals)
|
|
|
|
mIdleList[i].mHandler->IsLocal(&isGuarded);
|
|
|
|
if (!isGuarded)
|
|
|
|
DetachSocket(mIdleList, &mIdleList[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSocketTransportService::DoPollIteration(bool wait)
|
2006-05-10 17:30:15 +00:00
|
|
|
{
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("STS poll iter [%d]\n", wait));
|
2006-05-10 17:30:15 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i, count;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// poll loop
|
2006-05-10 17:30:15 +00:00
|
|
|
//
|
|
|
|
// walk active list backwards to see if any sockets should actually be
|
|
|
|
// idle, then walk the idle list backwards to see if any idle sockets
|
|
|
|
// should become active. take care to check only idle sockets that
|
|
|
|
// were idle to begin with ;-)
|
|
|
|
//
|
|
|
|
count = mIdleCount;
|
|
|
|
for (i=mActiveCount-1; i>=0; --i) {
|
|
|
|
//---
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" active [%u] { handler=%x condition=%x pollflags=%hu }\n", i,
|
2006-05-10 17:30:15 +00:00
|
|
|
mActiveList[i].mHandler,
|
|
|
|
mActiveList[i].mHandler->mCondition,
|
|
|
|
mActiveList[i].mHandler->mPollFlags));
|
|
|
|
//---
|
|
|
|
if (NS_FAILED(mActiveList[i].mHandler->mCondition))
|
2011-04-13 12:59:29 +00:00
|
|
|
DetachSocket(mActiveList, &mActiveList[i]);
|
2006-05-10 17:30:15 +00:00
|
|
|
else {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t in_flags = mActiveList[i].mHandler->mPollFlags;
|
2006-05-10 17:30:15 +00:00
|
|
|
if (in_flags == 0)
|
|
|
|
MoveToIdleList(&mActiveList[i]);
|
2003-02-23 05:07:34 +00:00
|
|
|
else {
|
2006-05-10 17:30:15 +00:00
|
|
|
// update poll flags
|
|
|
|
mPollList[i+1].in_flags = in_flags;
|
|
|
|
mPollList[i+1].out_flags = 0;
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
for (i=count-1; i>=0; --i) {
|
|
|
|
//---
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" idle [%u] { handler=%x condition=%x pollflags=%hu }\n", i,
|
2006-05-10 17:30:15 +00:00
|
|
|
mIdleList[i].mHandler,
|
|
|
|
mIdleList[i].mHandler->mCondition,
|
|
|
|
mIdleList[i].mHandler->mPollFlags));
|
|
|
|
//---
|
|
|
|
if (NS_FAILED(mIdleList[i].mHandler->mCondition))
|
2011-04-13 12:59:29 +00:00
|
|
|
DetachSocket(mIdleList, &mIdleList[i]);
|
2006-05-10 17:30:15 +00:00
|
|
|
else if (mIdleList[i].mHandler->mPollFlags != 0)
|
|
|
|
MoveToPollList(&mIdleList[i]);
|
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" calling PR_Poll [active=%u idle=%u]\n", mActiveCount, mIdleCount));
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2011-10-25 15:36:49 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// 30 active connections is the historic limit before firefox 7's 256. A few
|
|
|
|
// windows systems have troubles with the higher limit, so actively probe a
|
|
|
|
// limit the first time we exceed 30.
|
|
|
|
if ((mActiveCount > 30) && !mProbedMaxCount)
|
|
|
|
ProbeMaxCount();
|
|
|
|
#endif
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// Measures seconds spent while blocked on PR_Poll
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t pollInterval;
|
2005-01-26 02:13:14 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t n = Poll(wait, &pollInterval);
|
2006-05-10 17:30:15 +00:00
|
|
|
if (n < 0) {
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG((" PR_Poll error [%d]\n", PR_GetError()));
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//
|
|
|
|
// service "active" sockets...
|
|
|
|
//
|
2012-08-22 15:56:38 +00:00
|
|
|
for (i=0; i<int32_t(mActiveCount); ++i) {
|
2006-05-10 17:30:15 +00:00
|
|
|
PRPollDesc &desc = mPollList[i+1];
|
|
|
|
SocketContext &s = mActiveList[i];
|
|
|
|
if (n > 0 && desc.out_flags != 0) {
|
|
|
|
s.mElapsedTime = 0;
|
|
|
|
s.mHandler->OnSocketReady(desc.fd, desc.out_flags);
|
|
|
|
}
|
|
|
|
// check for timeout errors unless disabled...
|
2012-09-28 06:57:33 +00:00
|
|
|
else if (s.mHandler->mPollTimeout != UINT16_MAX) {
|
2006-05-10 17:30:15 +00:00
|
|
|
// update elapsed time counter
|
2012-09-28 06:57:33 +00:00
|
|
|
if (NS_UNLIKELY(pollInterval > (UINT16_MAX - s.mElapsedTime)))
|
|
|
|
s.mElapsedTime = UINT16_MAX;
|
2006-05-10 17:30:15 +00:00
|
|
|
else
|
2012-08-22 15:56:38 +00:00
|
|
|
s.mElapsedTime += uint16_t(pollInterval);
|
2006-05-10 17:30:15 +00:00
|
|
|
// check for timeout expiration
|
|
|
|
if (s.mElapsedTime >= s.mHandler->mPollTimeout) {
|
2005-01-26 02:13:14 +00:00
|
|
|
s.mElapsedTime = 0;
|
2006-05-10 17:30:15 +00:00
|
|
|
s.mHandler->OnSocketReady(desc.fd, -1);
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
//
|
|
|
|
// check for "dead" sockets and remove them (need to do this in
|
|
|
|
// reverse order obviously).
|
|
|
|
//
|
|
|
|
for (i=mActiveCount-1; i>=0; --i) {
|
|
|
|
if (NS_FAILED(mActiveList[i].mHandler->mCondition))
|
2011-04-13 12:59:29 +00:00
|
|
|
DetachSocket(mActiveList, &mActiveList[i]);
|
2006-05-10 17:30:15 +00:00
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
if (n != 0 && mPollList[0].out_flags == PR_POLL_READ) {
|
|
|
|
// acknowledge pollable event (wait should not block)
|
2007-05-30 17:30:39 +00:00
|
|
|
if (PR_WaitForPollableEvent(mThreadEvent) != PR_SUCCESS) {
|
|
|
|
// On Windows, the TCP loopback connection in the
|
|
|
|
// pollable event may become broken when a laptop
|
|
|
|
// switches between wired and wireless networks or
|
|
|
|
// wakes up from hibernation. We try to create a
|
|
|
|
// new pollable event. If that fails, we fall back
|
|
|
|
// on "busy wait".
|
2007-08-26 20:14:57 +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
|
|
|
MutexAutoLock lock(mLock);
|
2007-08-26 20:14:57 +00:00
|
|
|
PR_DestroyPollableEvent(mThreadEvent);
|
|
|
|
mThreadEvent = PR_NewPollableEvent();
|
|
|
|
}
|
2007-05-30 17:30:39 +00:00
|
|
|
if (!mThreadEvent) {
|
|
|
|
NS_WARNING("running socket transport thread without "
|
|
|
|
"a pollable event");
|
2010-10-28 17:09:08 +00:00
|
|
|
SOCKET_LOG(("running socket transport thread without "
|
2007-05-30 17:30:39 +00:00
|
|
|
"a pollable event"));
|
|
|
|
}
|
|
|
|
mPollList[0].fd = mThreadEvent;
|
|
|
|
// mPollList[0].in_flags was already set to PR_POLL_READ
|
|
|
|
// in Run().
|
|
|
|
mPollList[0].out_flags = 0;
|
|
|
|
}
|
2003-02-06 21:20:26 +00:00
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-02-09 17:31:44 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSocketTransportService::UpdatePrefs()
|
|
|
|
{
|
|
|
|
mSendBufferSize = 0;
|
|
|
|
|
2012-01-17 01:48:29 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2009-02-09 17:31:44 +00:00
|
|
|
if (tmpPrefService) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t bufferSize;
|
2009-02-09 17:31:44 +00:00
|
|
|
nsresult rv = tmpPrefService->GetIntPref(SEND_BUFFER_PREF, &bufferSize);
|
|
|
|
if (NS_SUCCEEDED(rv) && bufferSize > 0)
|
|
|
|
mSendBufferSize = bufferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSocketTransportService::Observe(nsISupports *subject,
|
|
|
|
const char *topic,
|
|
|
|
const PRUnichar *data)
|
|
|
|
{
|
|
|
|
if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
|
|
|
UpdatePrefs();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSocketTransportService::GetSendBufferSize(int32_t *value)
|
2009-02-09 17:31:44 +00:00
|
|
|
{
|
|
|
|
*value = mSendBufferSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
/// ugly OS specific includes are placed at the bottom of the src for clarity
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#elif defined(XP_UNIX) && !defined(AIX) && !defined(NEXTSTEP) && !defined(QNX)
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-25 15:36:49 +00:00
|
|
|
// Right now the only need to do this is on windows.
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
void
|
|
|
|
nsSocketTransportService::ProbeMaxCount()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
|
|
|
|
|
|
|
|
if (mProbedMaxCount)
|
|
|
|
return;
|
|
|
|
mProbedMaxCount = true;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t startedMaxCount = gMaxCount;
|
2011-10-25 15:36:49 +00:00
|
|
|
|
|
|
|
// Allocate and test a PR_Poll up to the gMaxCount number of unconnected
|
|
|
|
// sockets. See bug 692260 - windows should be able to handle 1000 sockets
|
|
|
|
// in select() without a problem, but LSPs have been known to balk at lower
|
|
|
|
// numbers. (64 in the bug).
|
|
|
|
|
|
|
|
// Allocate
|
|
|
|
struct PRPollDesc pfd[SOCKET_LIMIT_TARGET];
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t numAllocated = 0;
|
2011-10-25 15:36:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t index = 0 ; index < gMaxCount; ++index) {
|
2011-10-25 15:36:49 +00:00
|
|
|
pfd[index].in_flags = PR_POLL_READ | PR_POLL_WRITE | PR_POLL_EXCEPT;
|
|
|
|
pfd[index].out_flags = 0;
|
|
|
|
pfd[index].fd = PR_OpenTCPSocket(PR_AF_INET);
|
|
|
|
if (!pfd[index].fd) {
|
|
|
|
SOCKET_LOG(("Socket Limit Test index %d failed\n", index));
|
|
|
|
if (index < SOCKET_LIMIT_MIN)
|
|
|
|
gMaxCount = SOCKET_LIMIT_MIN;
|
|
|
|
else
|
|
|
|
gMaxCount = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++numAllocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test
|
|
|
|
PR_STATIC_ASSERT(SOCKET_LIMIT_MIN >= 32U);
|
|
|
|
while (gMaxCount <= numAllocated) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t rv = PR_Poll(pfd, gMaxCount, PR_MillisecondsToInterval(0));
|
2011-10-25 15:36:49 +00:00
|
|
|
|
|
|
|
SOCKET_LOG(("Socket Limit Test poll() size=%d rv=%d\n",
|
|
|
|
gMaxCount, rv));
|
|
|
|
|
|
|
|
if (rv >= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
SOCKET_LOG(("Socket Limit Test poll confirmationSize=%d rv=%d error=%d\n",
|
|
|
|
gMaxCount, rv, PR_GetError()));
|
|
|
|
|
|
|
|
gMaxCount -= 32;
|
|
|
|
if (gMaxCount <= SOCKET_LIMIT_MIN) {
|
|
|
|
gMaxCount = SOCKET_LIMIT_MIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t index = 0 ; index < numAllocated; ++index)
|
2011-10-25 15:36:49 +00:00
|
|
|
if (pfd[index].fd)
|
|
|
|
PR_Close(pfd[index].fd);
|
|
|
|
|
|
|
|
SOCKET_LOG(("Socket Limit Test max was confirmed at %d\n", gMaxCount));
|
|
|
|
}
|
|
|
|
#endif // windows
|
|
|
|
|
2011-04-13 12:59:29 +00:00
|
|
|
PRStatus
|
|
|
|
nsSocketTransportService::DiscoverMaxCount()
|
|
|
|
{
|
|
|
|
gMaxCount = SOCKET_LIMIT_MIN;
|
|
|
|
|
|
|
|
#if defined(XP_UNIX) && !defined(AIX) && !defined(NEXTSTEP) && !defined(QNX)
|
|
|
|
// On unix and os x network sockets and file
|
|
|
|
// descriptors are the same. OS X comes defaulted at 256,
|
|
|
|
// most linux at 1000. We can reliably use [sg]rlimit to
|
|
|
|
// query that and raise it. We will try to raise it 250 past
|
|
|
|
// our target number of SOCKET_LIMIT_TARGET so that some descriptors
|
|
|
|
// are still available for other things.
|
|
|
|
|
|
|
|
struct rlimit rlimitData;
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rlimitData) == -1)
|
|
|
|
return PR_SUCCESS;
|
|
|
|
if (rlimitData.rlim_cur >= SOCKET_LIMIT_TARGET + 250) {
|
|
|
|
gMaxCount = SOCKET_LIMIT_TARGET;
|
|
|
|
return PR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t maxallowed = rlimitData.rlim_max;
|
2011-04-13 12:59:29 +00:00
|
|
|
if (maxallowed == -1) { /* no limit */
|
|
|
|
maxallowed = SOCKET_LIMIT_TARGET + 250;
|
2012-08-22 15:56:38 +00:00
|
|
|
} else if ((uint32_t)maxallowed < SOCKET_LIMIT_MIN + 250) {
|
2011-04-13 12:59:29 +00:00
|
|
|
return PR_SUCCESS;
|
2012-08-22 15:56:38 +00:00
|
|
|
} else if ((uint32_t)maxallowed > SOCKET_LIMIT_TARGET + 250) {
|
2011-04-13 12:59:29 +00:00
|
|
|
maxallowed = SOCKET_LIMIT_TARGET + 250;
|
|
|
|
}
|
|
|
|
|
|
|
|
rlimitData.rlim_cur = maxallowed;
|
|
|
|
setrlimit(RLIMIT_NOFILE, &rlimitData);
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rlimitData) != -1)
|
|
|
|
if (rlimitData.rlim_cur > SOCKET_LIMIT_MIN + 250)
|
|
|
|
gMaxCount = rlimitData.rlim_cur - 250;
|
|
|
|
|
|
|
|
#elif defined(XP_WIN) && !defined(WIN_CE)
|
|
|
|
// >= XP is confirmed to have at least 1000
|
2012-02-23 14:53:55 +00:00
|
|
|
gMaxCount = SOCKET_LIMIT_TARGET;
|
2011-04-13 12:59:29 +00:00
|
|
|
#else
|
|
|
|
// other platforms are harder to test - so leave at safe legacy value
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return PR_SUCCESS;
|
|
|
|
}
|