(trunk libT) #2151: possible fix for "Unusually high CPU usage in latest builds" issue

This commit is contained in:
Charles Kerr 2009-06-06 16:19:34 +00:00
parent 8be9e3a44a
commit 3f03f2e0c3
1 changed files with 12 additions and 8 deletions

View File

@ -599,20 +599,24 @@ tr_fdSocketAccept( int b,
tr_address * addr, tr_address * addr,
tr_port * port ) tr_port * port )
{ {
int s = -1; int s;
unsigned int len; unsigned int len;
struct sockaddr_storage sock; struct sockaddr_storage sock;
tr_lockLock( gFd->lock );
assert( addr ); assert( addr );
assert( port ); assert( port );
tr_lockLock( gFd->lock ); len = sizeof( struct sockaddr_storage );
if( gFd->socketCount < getSocketMax( gFd ) ) s = accept( b, (struct sockaddr *) &sock, &len );
if( ( s >= 0 ) && gFd->socketCount < getSocketMax( gFd ) )
{ {
len = sizeof( struct sockaddr_storage ); EVUTIL_CLOSESOCKET( s );
s = accept( b, (struct sockaddr *) &sock, &len ); s = -1;
} }
if( s > -1 )
if( s >= 0 )
{ {
/* "The ss_family field of the sockaddr_storage structure will always /* "The ss_family field of the sockaddr_storage structure will always
* align with the family field of any protocol-specific structure." */ * align with the family field of any protocol-specific structure." */
@ -632,8 +636,8 @@ tr_fdSocketAccept( int b,
} }
++gFd->socketCount; ++gFd->socketCount;
} }
tr_lockUnlock( gFd->lock );
tr_lockUnlock( gFd->lock );
return s; return s;
} }