]> git.sur5r.net Git - openldap/commitdiff
Count writers, don't pass w fd_set if there are none
authorHoward Chu <hyc@openldap.org>
Thu, 18 Nov 2004 00:19:52 +0000 (00:19 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 18 Nov 2004 00:19:52 +0000 (00:19 +0000)
Deleted broken/unused FD_MANUAL_COPY code

servers/slapd/daemon.c

index 87e65ecfd230fde946bd3b8adc543d3b5eb62e0e..0d386bf2ef773a65fa4a01563bb6ab6747ac1535 100644 (file)
@@ -91,6 +91,7 @@ static struct slap_daemon {
                so don't bother with this optimization */
        int sd_nfds;
 #endif
+       int sd_nwriters;
 
        fd_set sd_actives;
        fd_set sd_readers;
@@ -244,16 +245,19 @@ static void slapd_add(ber_socket_t s, int isactive) {
  * Remove the descriptor from daemon control
  */
 void slapd_remove(ber_socket_t s, int wasactive, int wake) {
+       int waswriter;
        ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
 
        if ( wasactive ) {
                slap_daemon.sd_nactives--;
        }
+       waswriter = FD_ISSET(s, &slap_daemon.sd_writers);
 
        Debug( LDAP_DEBUG_CONNS, "daemon: removing %ld%s%s\n",
                (long) s,
            FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
-               FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
+               waswriter ? "w" : "" );
+       if ( waswriter ) slap_daemon.sd_nwriters--;
        FD_CLR( s, &slap_daemon.sd_actives );
        FD_CLR( s, &slap_daemon.sd_readers );
        FD_CLR( s, &slap_daemon.sd_writers );
@@ -288,7 +292,10 @@ void slapd_clr_write(ber_socket_t s, int wake) {
        ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
 
        assert( FD_ISSET( s, &slap_daemon.sd_actives) );
-       FD_CLR( s, &slap_daemon.sd_writers );
+       if ( FD_ISSET( s, &slap_daemon.sd_writers )) {
+               FD_CLR( s, &slap_daemon.sd_writers );
+               slap_daemon.sd_nwriters--;
+       }
 
        ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
        WAKE_LISTENER(wake);
@@ -298,8 +305,10 @@ void slapd_set_write(ber_socket_t s, int wake) {
        ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
 
        assert( FD_ISSET( s, &slap_daemon.sd_actives) );
-       if (!FD_ISSET(s, &slap_daemon.sd_writers))
-           FD_SET( (unsigned) s, &slap_daemon.sd_writers );
+       if (!FD_ISSET(s, &slap_daemon.sd_writers)) {
+               FD_SET( (unsigned) s, &slap_daemon.sd_writers );
+               slap_daemon.sd_nwriters++;
+       }
 
        ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
        WAKE_LISTENER(wake);
@@ -1108,7 +1117,7 @@ slapd_daemon_task(
 
        while ( !slapd_shutdown ) {
                ber_socket_t i;
-               int ns;
+               int ns, nwriters;
                int at;
                ber_socket_t nfds, nrfds, nwfds;
 #define SLAPD_EBADF_LIMIT 16
@@ -1157,26 +1166,14 @@ slapd_daemon_task(
                }
 #endif
 
-               FD_ZERO( &writefds );
-               FD_ZERO( &readfds );
-
                at = 0;
 
                ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
 
-#ifdef FD_SET_MANUAL_COPY
-               for( s = 0; s < nfds; s++ ) {
-                       if(FD_ISSET( &slap_sd_readers, s )) {
-                               FD_SET( s, &readfds );
-                       }
-                       if(FD_ISSET( &slap_sd_writers, s )) {
-                               FD_SET( s, &writefds );
-                       }
-               }
-#else
+               nwriters = slap_daemon.sd_nwriters;
                AC_MEMCPY( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) );
-               AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
-#endif
+               if ( nwriters )
+                       AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
                assert(!FD_ISSET(wake_sds[0], &readfds));
                FD_SET( wake_sds[0], &readfds );
 
@@ -1248,13 +1245,7 @@ slapd_daemon_task(
                                        tvp == NULL ? "NULL" : "zero" );
                }
 
-               switch(ns = select( nfds, &readfds,
-#ifdef HAVE_WINSOCK
-                       /* don't pass empty fd_set */
-                       ( writefds.fd_count > 0 ? &writefds : NULL ),
-#else
-                       &writefds,
-#endif
+               switch(ns = select( nfds, &readfds, nwriters > 0 ? &writefds : NULL,
                        NULL, tvp ))
                {
                case -1: {      /* failure - try again */
@@ -1660,7 +1651,10 @@ slapd_daemon_task(
                         */
 
                        if ( connection_write( wd ) < 0 ) {
-                               FD_CLR( (unsigned) wd, &readfds );
+                               if ( FD_ISSET( wd, &readfds )) {
+                                       FD_CLR( (unsigned) wd, &readfds );
+                                       nrfds--;
+                               }
                                slapd_close( wd );
                        }
                }