assert( mc->mc_refcnt == 1 );
mc = avl_delete( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
- meta_back_conn_cmp );
+ meta_back_dnconn_cmp );
assert( mc != NULL );
ber_bvreplace( &mc->mc_local_ndn, &op->o_req_ndn );
lerr = avl_insert( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
- meta_back_conn_cmp, meta_back_conn_dup );
+ meta_back_dnconn_cmp, meta_back_dnconn_dup );
ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
if ( lerr == -1 ) {
for ( i = 0; i < mi->mi_ntargets; ++i ) {
#define PRINT_CONNTREE 0
/*
- * meta_back_conn_cmp
+ * meta_back_dnconn_cmp
*
- * compares two struct metaconn based on the value of the conn pointer;
- * used by avl stuff
+ * compares two struct metaconn based on the value of the conn pointer
+ * and of the local DN; used by avl stuff
*/
int
-meta_back_conn_cmp(
+meta_back_dnconn_cmp(
const void *c1,
const void *c2 )
{
int rc;
/* If local DNs don't match, it is definitely not a match */
- rc = ber_bvcmp( &mc1->mc_local_ndn, &mc2->mc_local_ndn );
- if ( rc ) {
- return rc;
+ /* For shared sessions, conn is NULL. Only explicitly
+ * bound sessions will have non-NULL conn.
+ */
+ rc = SLAP_PTRCMP( mc1->mc_conn, mc2->mc_conn );
+ if ( rc == 0 ) {
+ rc = ber_bvcmp( &mc1->mc_local_ndn, &mc2->mc_local_ndn );
}
+ return rc;
+}
+
+/*
+ * meta_back_conn_cmp
+ *
+ * compares two struct metaconn based on the value of the conn pointer;
+ * used by avl stuff
+ */
+int
+meta_back_conn_cmp(
+ const void *c1,
+ const void *c2 )
+{
+ metaconn_t *mc1 = ( metaconn_t * )c1;
+ metaconn_t *mc2 = ( metaconn_t * )c2;
+
/* For shared sessions, conn is NULL. Only explicitly
* bound sessions will have non-NULL conn.
*/
}
/*
- * meta_back_conn_dup
+ * meta_back_dnconn_dup
*
* returns -1 in case a duplicate struct metaconn has been inserted;
* used by avl stuff
*/
int
-meta_back_conn_dup(
+meta_back_dnconn_dup(
void *c1,
void *c2 )
{
metaconn_t *mc2 = ( metaconn_t * )c2;
/* Cannot have more than one shared session with same DN */
- if ( dn_match( &mc1->mc_local_ndn, &mc2->mc_local_ndn ) &&
- mc1->mc_conn == mc2->mc_conn )
+ if ( mc1->mc_conn == mc2->mc_conn &&
+ dn_match( &mc1->mc_local_ndn, &mc2->mc_local_ndn ) )
{
return -1;
}
retry_lock:
ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
mc = (metaconn_t *)avl_find( mi->mi_conninfo.lai_tree,
- (caddr_t)&mc_curr, meta_back_conn_cmp );
+ (caddr_t)&mc_curr, meta_back_dnconn_cmp );
if ( mc ) {
if ( mc->mc_tainted ) {
rs->sr_err = LDAP_UNAVAILABLE;
if ( !( sendok & LDAP_BACK_BINDING ) ) {
ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
mc = (metaconn_t *)avl_find( mi->mi_conninfo.lai_tree,
- (caddr_t)&mc_curr, meta_back_conn_cmp );
+ (caddr_t)&mc_curr, meta_back_dnconn_cmp );
if ( mc != NULL ) {
mc->mc_refcnt++;
}
*/
ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
err = avl_insert( &mi->mi_conninfo.lai_tree, ( caddr_t )mc,
- meta_back_conn_cmp, meta_back_conn_dup );
+ meta_back_dnconn_cmp, meta_back_dnconn_dup );
#if PRINT_CONNTREE > 0
myprint( mi->mi_conninfo.lai_tree );
LDAP_BACK_CONN_BINDING_CLEAR( mc );
if ( mc->mc_refcnt == 0 && mc->mc_tainted ) {
(void)avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )mc,
- meta_back_conn_cmp );
+ meta_back_dnconn_cmp );
meta_back_conn_free( mc );
}
ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
BER_BVISNULL( &conn->c_ndn ) ? "" : conn->c_ndn.bv_val, 0 );
mc_curr.mc_conn = conn;
- mc_curr.mc_local_ndn = conn->c_ndn;
ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
- mc = avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )&mc_curr,
- meta_back_conn_cmp );
- ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
-
- if ( mc ) {
+ while ( ( mc = avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )&mc_curr, meta_back_conn_cmp ) ) != NULL )
+ {
Debug( LDAP_DEBUG_TRACE,
"=>meta_back_conn_destroy: destroying conn %ld\n",
LDAP_BACK_PCONN_ID( mc->mc_conn ), 0, 0 );
meta_back_conn_free( mc );
}
+ ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
/*
* Cleanup rewrite session