From 941c492269b59160875d1097f20d764ff10efb09 Mon Sep 17 00:00:00 2001 From: "rpotts%netscape.com" Date: Thu, 3 Jun 1999 05:43:56 +0000 Subject: [PATCH] Added support for Suspend/Resume... --- netwerk/base/src/nsSocketTransport.cpp | 57 ++++++++++++++++++- netwerk/base/src/nsSocketTransport.h | 2 + netwerk/base/src/nsSocketTransportService.cpp | 2 +- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/netwerk/base/src/nsSocketTransport.cpp b/netwerk/base/src/nsSocketTransport.cpp index 207074849571..cd366fad0548 100644 --- a/netwerk/base/src/nsSocketTransport.cpp +++ b/netwerk/base/src/nsSocketTransport.cpp @@ -110,6 +110,8 @@ nsSocketTransport::nsSocketTransport() mSocketFD = nsnull; mLock = nsnull; + mSuspendCount = 0; + mCurrentState = eSocketState_Created; mOperation = eSocketOperation_None; mSelectFlags = 0; @@ -215,6 +217,15 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags) // Lock(); + // + // If the transport has been suspended, then return NS_OK immediately... + // This removes the transport from the select list... + // + if (mSuspendCount) { + done = PR_TRUE; + rv = NS_OK; + } + while (!done) { switch (mCurrentState) { @@ -714,13 +725,55 @@ nsSocketTransport::Cancel(void) NS_IMETHODIMP nsSocketTransport::Suspend(void) { - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv = NS_OK; + + // Enter the socket transport lock... + Lock(); + + mSuspendCount += 1; + // + // Wake up the transport on the socket transport thread so it can + // be removed from the select list... + // + // Only do this the first time a transport is suspended... + // + if (1 == mSuspendCount) { + rv = mService->AddToWorkQ(this); + } + + // Leave the socket transport lock... + Unlock(); + + return rv; } + NS_IMETHODIMP nsSocketTransport::Resume(void) { - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv = NS_OK; + + // Enter the socket transport lock... + Lock(); + + if (mSuspendCount) { + mSuspendCount -= 1; + // + // Wake up the transport on the socket transport thread so it can + // be resumed... + // + if (0 == mSuspendCount) { + rv = mService->AddToWorkQ(this); + } + } else { + // Only a suspended transport can be resumed... + rv = NS_ERROR_FAILURE; + } + + // Leave the socket transport lock... + Unlock(); + + return rv; } diff --git a/netwerk/base/src/nsSocketTransport.h b/netwerk/base/src/nsSocketTransport.h index 1d31cf809f41..db4a0cf813ba 100644 --- a/netwerk/base/src/nsSocketTransport.h +++ b/netwerk/base/src/nsSocketTransport.h @@ -109,6 +109,8 @@ protected: PRLock* mLock; nsSocketState mCurrentState; nsSocketOperation mOperation; + + PRInt32 mSuspendCount; PRFileDesc* mSocketFD; PRNetAddr mNetAddress; diff --git a/netwerk/base/src/nsSocketTransportService.cpp b/netwerk/base/src/nsSocketTransportService.cpp index be6271578bb2..d11898c5e477 100644 --- a/netwerk/base/src/nsSocketTransportService.cpp +++ b/netwerk/base/src/nsSocketTransportService.cpp @@ -21,7 +21,7 @@ #include "nsSocketTransport.h" -#define MAX_OPEN_CONNECTIONS 10 +#define MAX_OPEN_CONNECTIONS 50 static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);