1
From 33f6bc4fe623a2fdef02de1a84fdb93de1aad32a Mon Sep 17 00:00:00 2001
2
From: Howard Chu <hyc@openldap.org>
3
Date: Mon, 20 Feb 2012 14:51:30 -0800
4
Subject: [PATCH] ITS#7167 only poll sockets for write as needed
7
libraries/libldap/ldap-int.h | 1 +
8
libraries/libldap/open.c | 2 --
9
libraries/libldap/os-ip.c | 26 ++++++++++++++++++++++++++
10
libraries/libldap/request.c | 1 +
11
libraries/libldap/result.c | 6 +++---
12
5 files changed, 31 insertions(+), 5 deletions(-)
14
diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h
15
index c558d2a..ad37250 100644
16
--- a/libraries/libldap/ldap-int.h
17
+++ b/libraries/libldap/ldap-int.h
18
@@ -622,6 +622,7 @@ LDAP_F (void) ldap_free_select_info( void *sip );
19
LDAP_F (void) ldap_mark_select_write( LDAP *ld, Sockbuf *sb );
20
LDAP_F (void) ldap_mark_select_read( LDAP *ld, Sockbuf *sb );
21
LDAP_F (void) ldap_mark_select_clear( LDAP *ld, Sockbuf *sb );
22
+LDAP_F (void) ldap_clear_select_write( LDAP *ld, Sockbuf *sb );
23
LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
24
LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
26
diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c
27
index 6b92ba6..a920953 100644
28
--- a/libraries/libldap/open.c
29
+++ b/libraries/libldap/open.c
30
@@ -344,7 +344,6 @@ ldap_init_fd(
32
/* Add the connection to the *LDAP's select pool */
33
ldap_mark_select_read( ld, conn->lconn_sb );
34
- ldap_mark_select_write( ld, conn->lconn_sb );
38
@@ -502,7 +501,6 @@ ldap_open_internal_connection( LDAP **ldp, ber_socket_t *fdp )
40
/* Add the connection to the *LDAP's select pool */
41
ldap_mark_select_read( ld, c->lconn_sb );
42
- ldap_mark_select_write( ld, c->lconn_sb );
44
/* Make this connection an LDAP V3 protocol connection */
46
diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c
47
index daa765e..2864256 100644
48
--- a/libraries/libldap/os-ip.c
49
+++ b/libraries/libldap/os-ip.c
50
@@ -966,6 +966,32 @@ ldap_mark_select_clear( LDAP *ld, Sockbuf *sb )
55
+ldap_clear_select_write( LDAP *ld, Sockbuf *sb )
57
+ struct selectinfo *sip;
60
+ sip = (struct selectinfo *)ld->ld_selectinfo;
62
+ ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
65
+ /* for UNIX poll(2) */
68
+ for(i=0; i < sip->si_maxfd; i++) {
69
+ if( sip->si_fds[i].fd == sd ) {
70
+ sip->si_fds[i].events &= ~POLL_WRITE;
75
+ /* for UNIX select(2) */
76
+ FD_CLR( sd, &sip->si_writefds );
82
ldap_is_write_ready( LDAP *ld, Sockbuf *sb )
83
diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c
84
index 88190a2..071391d 100644
85
--- a/libraries/libldap/request.c
86
+++ b/libraries/libldap/request.c
87
@@ -202,6 +202,7 @@ ldap_int_flush_request(
89
/* sent -- waiting for a response */
90
ldap_mark_select_read( ld, lc->lconn_sb );
91
+ ldap_clear_select_write( ld, lc->lconn_sb );
95
diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c
96
index b6e8e75..7241df9 100644
97
--- a/libraries/libldap/result.c
98
+++ b/libraries/libldap/result.c
99
@@ -302,7 +302,7 @@ wait4msg(
100
if ( ber_sockbuf_ctrl( lc->lconn_sb,
101
LBER_SB_OPT_DATA_READY, NULL ) )
104
+ lc_ready = 2; /* ready at ber level, not socket level */
108
@@ -373,8 +373,8 @@ wait4msg(
111
LDAP_MUTEX_UNLOCK( &ld->ld_req_mutex );
112
- /* Quit looping if no one handled any events */
114
+ /* Quit looping if no one handled any socket events */
115
+ if (!serviced && lc_ready == 1)
118
LDAP_MUTEX_UNLOCK( &ld->ld_conn_mutex );