- ber_dupbv( &lc->conns[ candidate ].bound_dn, &op->o_req_dn );
- lc->conns[ candidate ].bound = META_BOUND;
- lc->bound_target = candidate;
-
- if ( li->savecred ) {
- if ( lc->conns[ candidate ].cred.bv_val )
- ch_free( lc->conns[ candidate ].cred.bv_val );
- ber_dupbv( &lc->conns[ candidate ].cred,
- &op->oq_bind.rb_cred );
- ldap_set_rebind_proc( lc->conns[ candidate ].ld,
- meta_back_rebind,
- &lc->conns[ candidate ] );
- }
+retry:;
+ tv.tv_sec = 0;
+ tv.tv_usec = META_BIND_TIMEOUT;
+ switch ( ldap_result( msc->msc_ld, msgid, 0, &tv, &res ) ) {
+ case 0:
+ Debug( LDAP_DEBUG_ANY, "%s meta_back_single_bind: ldap_result=%d nretries=%d\n",
+ op->o_log_prefix, 0, nretries );
+
+ if ( nretries != META_RETRY_NEVER ) {
+ ldap_pvt_thread_yield();
+ if ( nretries > 0 ) {
+ nretries--;
+ }
+ goto retry;
+ }
+ rs->sr_err = LDAP_BUSY;
+ if ( rebinding ) {
+ ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
+ break;
+ }
+
+ /* FIXME: some times the request times out
+ * while the other party is not willing to
+ * send a response any more. Give it a second
+ * chance with a freshly bound connection */
+ rebinding = 1;
+ nretries = mt->mt_nretries;
+ /* fallthru */
+
+ case -1:
+ ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
+ &rs->sr_err );
+
+ if ( rebinding ) {
+ ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
+ }
+
+ Debug( LDAP_DEBUG_ANY, "### %s meta_back_single_bind: err=%d nretries=%d\n",
+ op->o_log_prefix, rs->sr_err, nretries );
+
+ rc = slap_map_api2result( rs );
+ if ( rs->sr_err == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
+ ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
+ msc->msc_ld = NULL;
+ msc->msc_bound = 0;
+
+ /* mc here must be the regular mc, reset and ready for init */
+ rc = meta_back_init_one_conn( op, rs, mt, msc,
+ LDAP_BACK_DONTSEND );
+ if ( rc ) {
+ if ( nretries > 0 ) {
+ nretries--;
+ }
+ ldap_pvt_thread_yield();
+ goto rebind;
+ }
+ }
+ break;