Bug 141614: restored Matthew Zahorik's net_server nonblocking connect

logic, which accidentally got deleted when the BONE changes were checked
in. This patch was contributed by Arougthopher
<arougthopher@lizardland.net>.
Modified Files: bfile.c bmisc.c bnet.c
This commit is contained in:
wtc%netscape.com 2002-07-17 06:04:42 +00:00
parent 937dfac4d5
commit d171294dd7
3 changed files with 69 additions and 7 deletions

View File

@ -741,6 +741,56 @@ _MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
out_flags |= PR_POLL_WRITE;
}
if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
/* Workaround for nonblocking connects under net_server */
#ifndef BONE_VERSION
if (out_flags)
{
/* check if it is a pending connect */
int i = 0, j = 0;
PR_Lock( _connectLock );
for( i = 0; i < connectCount; i++ )
{
if(connectList[i].osfd == osfd)
{
int connectError;
int connectResult;
connectResult = connect(connectList[i].osfd,
&connectList[i].addr,
connectList[i].addrlen);
connectError = errno;
if(connectResult < 0 )
{
if(connectError == EINTR || connectError == EWOULDBLOCK ||
connectError == EINPROGRESS || connectError == EALREADY)
{
break;
}
}
if(i == (connectCount - 1))
{
connectList[i].osfd = -1;
} else {
for(j = i; j < connectCount; j++ )
{
memcpy( &connectList[j], &connectList[j+1],
sizeof(connectList[j]));
}
}
connectCount--;
bottom->secret->md.connectReturnValue = connectResult;
bottom->secret->md.connectReturnError = connectError;
bottom->secret->md.connectValueValid = PR_TRUE;
break;
}
}
PR_Unlock( _connectLock );
}
#endif
}
pd->out_flags = out_flags;
if (out_flags) ready++;

View File

@ -37,8 +37,12 @@
#include <stdlib.h>
PRLock *_connectLock = NULL;
#ifndef BONE_VERSION
/* Workaround for nonblocking connects under net_server */
PRUint32 connectCount = 0;
ConnectListNode connectList[64];
#endif
void
_MD_cleanup_before_exit (void)
@ -63,7 +67,10 @@ _MD_final_init (void)
{
_connectLock = PR_NewLock();
PR_ASSERT(NULL != _connectLock);
#ifndef BONE_VERSION
/* Workaround for nonblocking connects under net_server */
connectCount = 0;
#endif
}
void

View File

@ -585,13 +585,18 @@ retry:
if( fd->secret->nonblocking && ((err == EAGAIN) || (err == EINPROGRESS))) {
PR_Lock(_connectLock);
connectList[connectCount].osfd = osfd;
memcpy(&connectList[connectCount].addr, addr, addrlen);
connectList[connectCount].addrlen = addrlen;
connectList[connectCount].timeout = timeout;
connectCount++;
PR_Unlock(_connectLock);
_PR_MD_MAP_CONNECT_ERROR(err);
if (connectCount < sizeof(connectList)/sizeof(connectList[0])) {
connectList[connectCount].osfd = osfd;
memcpy(&connectList[connectCount].addr, addr, addrlen);
connectList[connectCount].addrlen = addrlen;
connectList[connectCount].timeout = timeout;
connectCount++;
PR_Unlock(_connectLock);
_PR_MD_MAP_CONNECT_ERROR(err);
} else {
PR_Unlock(_connectLock);
PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
}
return rv;
}
#else /* BONE_VERSION */