Added support for Suspend/Resume...

This commit is contained in:
rpotts%netscape.com 1999-06-03 05:43:56 +00:00
Родитель 69710c988d
Коммит 941c492269
3 изменённых файлов: 58 добавлений и 3 удалений

Просмотреть файл

@ -110,6 +110,8 @@ nsSocketTransport::nsSocketTransport()
mSocketFD = nsnull; mSocketFD = nsnull;
mLock = nsnull; mLock = nsnull;
mSuspendCount = 0;
mCurrentState = eSocketState_Created; mCurrentState = eSocketState_Created;
mOperation = eSocketOperation_None; mOperation = eSocketOperation_None;
mSelectFlags = 0; mSelectFlags = 0;
@ -215,6 +217,15 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
// //
Lock(); 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) while (!done)
{ {
switch (mCurrentState) { switch (mCurrentState) {
@ -714,13 +725,55 @@ nsSocketTransport::Cancel(void)
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransport::Suspend(void) 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 NS_IMETHODIMP
nsSocketTransport::Resume(void) 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;
} }

Просмотреть файл

@ -110,6 +110,8 @@ protected:
nsSocketState mCurrentState; nsSocketState mCurrentState;
nsSocketOperation mOperation; nsSocketOperation mOperation;
PRInt32 mSuspendCount;
PRFileDesc* mSocketFD; PRFileDesc* mSocketFD;
PRNetAddr mNetAddress; PRNetAddr mNetAddress;
PRInt16 mSelectFlags; PRInt16 mSelectFlags;

Просмотреть файл

@ -21,7 +21,7 @@
#include "nsSocketTransport.h" #include "nsSocketTransport.h"
#define MAX_OPEN_CONNECTIONS 10 #define MAX_OPEN_CONNECTIONS 50
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);