]> git.sur5r.net Git - openldap/commitdiff
ITS#7167 only poll sockets for write as needed
authorHoward Chu <hyc@openldap.org>
Mon, 20 Feb 2012 22:51:30 +0000 (14:51 -0800)
committerHoward Chu <hyc@openldap.org>
Mon, 20 Feb 2012 22:51:30 +0000 (14:51 -0800)
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/os-ip.c
libraries/libldap/request.c
libraries/libldap/result.c

index c558d2a3975848bf0b7bd837b63b62f5dc54458b..ad37250ad15a31762f0ec09fcc28ca7650942c82 100644 (file)
@@ -622,6 +622,7 @@ LDAP_F (void) ldap_free_select_info( void *sip );
 LDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
 LDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
 LDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
+LDAP_F (void) ldap_clear_select_write( LDAP *ld, Sockbuf *sb );
 LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
 LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
 
index 6b92ba68b7dd35ca4d473d9b7fe0ec05d5f53a9d..a92095334e91fab25d884dda576352699d528f9d 100644 (file)
@@ -344,7 +344,6 @@ ldap_init_fd(
 
        /* Add the connection to the *LDAP's select pool */
        ldap_mark_select_read( ld, conn->lconn_sb );
-       ldap_mark_select_write( ld, conn->lconn_sb );
        
        *ldp = ld;
        return LDAP_SUCCESS;
@@ -502,7 +501,6 @@ ldap_open_internal_connection( LDAP **ldp, ber_socket_t *fdp )
 
        /* Add the connection to the *LDAP's select pool */
        ldap_mark_select_read( ld, c->lconn_sb );
-       ldap_mark_select_write( ld, c->lconn_sb );
 
        /* Make this connection an LDAP V3 protocol connection */
        rc = LDAP_VERSION3;
index daa765e3fe76c4b083608d5f2003bd2b19906f6a..286425691650f865f630c5fd0b9e0c63571e7051 100644 (file)
@@ -966,6 +966,32 @@ ldap_mark_select_clear( LDAP *ld, Sockbuf *sb )
 #endif
 }
 
+void
+ldap_clear_select_write( LDAP *ld, Sockbuf *sb )
+{
+       struct selectinfo       *sip;
+       ber_socket_t            sd;
+
+       sip = (struct selectinfo *)ld->ld_selectinfo;
+
+       ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
+
+#ifdef HAVE_POLL
+       /* for UNIX poll(2) */
+       {
+               int i;
+               for(i=0; i < sip->si_maxfd; i++) {
+                       if( sip->si_fds[i].fd == sd ) {
+                               sip->si_fds[i].events &= ~POLL_WRITE;
+                       }
+               }
+       }
+#else
+       /* for UNIX select(2) */
+       FD_CLR( sd, &sip->si_writefds );
+#endif
+}
+
 
 int
 ldap_is_write_ready( LDAP *ld, Sockbuf *sb )
index 88190a2d36f482a7fc8300c8c69b99509f6c6bbc..071391d9abc1e3acb7f8fcd1a8e8e85bdaecad6c 100644 (file)
@@ -202,6 +202,7 @@ ldap_int_flush_request(
 
                /* sent -- waiting for a response */
                ldap_mark_select_read( ld, lc->lconn_sb );
+               ldap_clear_select_write( ld, lc->lconn_sb );
        }
        return 0;
 }
index b6e8e75105f89b2ac02d22bc8d00d6bc888e0fd8..7241df93f257ea3684dd977cfd6add5d8395ad61 100644 (file)
@@ -302,7 +302,7 @@ wait4msg(
                                if ( ber_sockbuf_ctrl( lc->lconn_sb,
                                        LBER_SB_OPT_DATA_READY, NULL ) )
                                {
-                                       lc_ready = 1;
+                                       lc_ready = 2;   /* ready at ber level, not socket level */
                                        break;
                                }
                        }
@@ -373,8 +373,8 @@ wait4msg(
                                        }
                                }
                                LDAP_MUTEX_UNLOCK( &ld->ld_req_mutex );
-                               /* Quit looping if no one handled any events */
-                               if (!serviced)
+                               /* Quit looping if no one handled any socket events */
+                               if (!serviced && lc_ready == 1)
                                        rc = -1;
                        }
                        LDAP_MUTEX_UNLOCK( &ld->ld_conn_mutex );