From 3f03f2e0c35a808270bf17036e5f01a917d30097 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 6 Jun 2009 16:19:34 +0000 Subject: [PATCH] (trunk libT) #2151: possible fix for "Unusually high CPU usage in latest builds" issue --- libtransmission/fdlimit.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 7ba406df8..9769ca453 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -599,20 +599,24 @@ tr_fdSocketAccept( int b, tr_address * addr, tr_port * port ) { - int s = -1; - unsigned int len; + int s; + unsigned int len; struct sockaddr_storage sock; + tr_lockLock( gFd->lock ); assert( addr ); assert( port ); - tr_lockLock( gFd->lock ); - if( gFd->socketCount < getSocketMax( gFd ) ) + len = sizeof( struct sockaddr_storage ); + s = accept( b, (struct sockaddr *) &sock, &len ); + + if( ( s >= 0 ) && gFd->socketCount < getSocketMax( gFd ) ) { - len = sizeof( struct sockaddr_storage ); - s = accept( b, (struct sockaddr *) &sock, &len ); + EVUTIL_CLOSESOCKET( s ); + s = -1; } - if( s > -1 ) + + if( s >= 0 ) { /* "The ss_family field of the sockaddr_storage structure will always * align with the family field of any protocol-specific structure." */ @@ -632,8 +636,8 @@ tr_fdSocketAccept( int b, } ++gFd->socketCount; } - tr_lockUnlock( gFd->lock ); + tr_lockUnlock( gFd->lock ); return s; }