LDAPMessage *ld_responses; /* list of outstanding responses */
#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_t ld_conn_mutex;
ldap_pvt_thread_mutex_t ld_req_mutex;
ldap_pvt_thread_mutex_t ld_res_mutex;
#endif
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_init( &ld->ld_req_mutex );
ldap_pvt_thread_mutex_init( &ld->ld_res_mutex );
+ ldap_pvt_thread_mutex_init( &ld->ld_conn_mutex );
#endif
*ldp = ld;
return LDAP_SUCCESS;
}
lc->lconn_status = LDAP_CONNST_CONNECTED;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
+#endif
lc->lconn_next = ld->ld_conns;
ld->ld_conns = lc;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
/*
* XXX for now, we always do a synchronous bind. This will have
LDAPConn *lc;
LDAPURLDesc *lcu, *lsu;
int lcu_port, lsu_port;
+ int found = 0;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
+#endif
for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
lcu = lc->lconn_server;
lcu_port = ldap_pvt_url_scheme_port( lcu->lud_scheme,
lsu_port = ldap_pvt_url_scheme_port( lsu->lud_scheme,
lsu->lud_port );
- if ( strcmp( lcu->lud_scheme, lsu->lud_scheme ) == 0
+ if ( lsu_port == lcu_port
+ && strcmp( lcu->lud_scheme, lsu->lud_scheme ) == 0
&& lcu->lud_host != NULL && *lcu->lud_host != '\0'
&& lsu->lud_host != NULL && *lsu->lud_host != '\0'
- && strcasecmp( lsu->lud_host, lcu->lud_host ) == 0
- && lsu_port == lcu_port )
+ && strcasecmp( lsu->lud_host, lcu->lud_host ) == 0 )
{
- return lc;
+ found = 1;
+ break;
}
if ( !any ) break;
}
+ if ( found )
+ break;
}
-
- return NULL;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
+ return lc;
}
ldap_int_sasl_close( ld, lc );
prevlc = NULL;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
+#endif
for ( tmplc = ld->ld_conns;
tmplc != NULL;
tmplc = tmplc->lconn_next )
}
prevlc = tmplc;
}
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
ldap_free_urllist( lc->lconn_server );
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
if ( lc->lconn_krbinstance != NULL ) {
} else {
int lc_ready = 0;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
+#endif
for ( lc = ld->ld_conns; lc != NULL; lc = nextlc ) {
nextlc = lc->lconn_next;
if ( ber_sockbuf_ctrl( lc->lconn_sb,
LBER_SB_OPT_DATA_READY, NULL ) ) {
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
rc = try_read1msg( ld, msgid, all, lc->lconn_sb,
&lc, result );
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
+#endif
lc_ready = 1;
break;
}
- }
+ }
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
if ( !lc_ready ) {
rc = ldap_int_select( ld, tvp );
}
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
#endif
for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
lc = nextlc )
if ( lc->lconn_status == LDAP_CONNST_CONNECTED &&
ldap_is_read_ready( ld, lc->lconn_sb ))
{
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
rc = try_read1msg( ld, msgid, all,
lc->lconn_sb, &lc, result );
if ( lc == NULL ) lc = nextlc;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
+#endif
}
}
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
+#endif
}
}
}