Slight tweak for select descriptor checking

This commit is contained in:
Howard Chu 2004-11-14 21:27:53 +00:00
parent a90e63fde0
commit a59243ceee

View file

@ -1115,7 +1115,7 @@ slapd_daemon_task(
ber_socket_t i; ber_socket_t i;
int ns; int ns;
int at; int at;
ber_socket_t nfds; ber_socket_t nfds, nrfds, nwfds;
#define SLAPD_EBADF_LIMIT 16 #define SLAPD_EBADF_LIMIT 16
int ebadf = 0; int ebadf = 0;
@ -1307,6 +1307,7 @@ slapd_daemon_task(
#if defined(NO_THREADS) || defined(HAVE_GNU_PTH) #if defined(NO_THREADS) || defined(HAVE_GNU_PTH)
waking = 0; waking = 0;
#endif #endif
ns--;
continue; continue;
} }
@ -1333,12 +1334,16 @@ slapd_daemon_task(
peername[0] = '\0'; peername[0] = '\0';
if ( ns <= 0 ) break;
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
continue; continue;
if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) ) if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
continue; continue;
ns--;
#ifdef LDAP_CONNECTIONLESS #ifdef LDAP_CONNECTIONLESS
if ( slap_listeners[l]->sl_is_udp ) { if ( slap_listeners[l]->sl_is_udp ) {
/* The first time we receive a query, we set this /* The first time we receive a query, we set this
@ -1592,9 +1597,17 @@ slapd_daemon_task(
continue; continue;
} }
/* bypass the following tests if no descriptors left */
if ( ns <= 0 ) {
ldap_pvt_thread_yield();
continue;
}
#ifdef LDAP_DEBUG #ifdef LDAP_DEBUG
Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 ); Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
#ifdef HAVE_WINSOCK #ifdef HAVE_WINSOCK
nrfds = readfds.fd_count;
nwfds = writefds.fd_count;
for ( i = 0; i < readfds.fd_count; i++ ) { for ( i = 0; i < readfds.fd_count; i++ ) {
Debug( LDAP_DEBUG_CONNS, " %d%s", Debug( LDAP_DEBUG_CONNS, " %d%s",
readfds.fd_array[i], "r", 0 ); readfds.fd_array[i], "r", 0 );
@ -1605,6 +1618,8 @@ slapd_daemon_task(
} }
#else #else
nrfds = 0;
nwfds = 0;
for ( i = 0; i < nfds; i++ ) { for ( i = 0; i < nfds; i++ ) {
int r, w; int r, w;
@ -1613,7 +1628,16 @@ slapd_daemon_task(
if ( r || w ) { if ( r || w ) {
Debug( LDAP_DEBUG_CONNS, " %d%s%s", i, Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
r ? "r" : "", w ? "w" : "" ); r ? "r" : "", w ? "w" : "" );
if ( r ) {
nrfds++;
ns--;
} }
if ( w ) {
nwfds++;
ns--;
}
}
if ( ns <= 0 ) break;
} }
#endif #endif
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 ); Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
@ -1621,11 +1645,7 @@ slapd_daemon_task(
#endif #endif
/* loop through the writers */ /* loop through the writers */
#ifdef HAVE_WINSOCK for ( i = 0; nwfds > 0; i++ )
for ( i = 0; i < writefds.fd_count; i++ )
#else
for ( i = 0; i < nfds; i++ )
#endif
{ {
ber_socket_t wd; ber_socket_t wd;
#ifdef HAVE_WINSOCK #ifdef HAVE_WINSOCK
@ -1636,6 +1656,7 @@ slapd_daemon_task(
} }
wd = i; wd = i;
#endif #endif
nwfds--;
Debug( LDAP_DEBUG_CONNS, Debug( LDAP_DEBUG_CONNS,
"daemon: write active on %d\n", "daemon: write active on %d\n",
@ -1653,11 +1674,7 @@ slapd_daemon_task(
} }
} }
#ifdef HAVE_WINSOCK for ( i = 0; nrfds > 0; i++ )
for ( i = 0; i < readfds.fd_count; i++ )
#else
for ( i = 0; i < nfds; i++ )
#endif
{ {
ber_socket_t rd; ber_socket_t rd;
#ifdef HAVE_WINSOCK #ifdef HAVE_WINSOCK
@ -1668,6 +1685,7 @@ slapd_daemon_task(
} }
rd = i; rd = i;
#endif #endif
nrfds--;
Debug ( LDAP_DEBUG_CONNS, Debug ( LDAP_DEBUG_CONNS,
"daemon: read activity on %d\n", rd, 0, 0 ); "daemon: read activity on %d\n", rd, 0, 0 );