]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/abandon.c
Sync with HEAD
[openldap] / libraries / libldap / abandon.c
index fa7c74efc2909974ba0f7042b2c9f227e57fd539..551940d1b1655dbbe13d3584db06cf2be8dd05ae 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -110,11 +110,11 @@ do_abandon(
        ber_int_t origid,
        ber_int_t msgid,
        LDAPControl **sctrls,
-       LDAPControl **cctrls)
+       LDAPControl **cctrls )
 {
        BerElement      *ber;
        int             i, err, sendabandon;
-       ber_int_t *old_abandon;
+       ber_int_t       *old_abandon;
        Sockbuf         *sb;
        LDAPRequest     *lr;
 
@@ -191,23 +191,24 @@ do_abandon(
                        i = ++(ld)->ld_msgid;
 #ifdef LDAP_CONNECTIONLESS
                        if ( LDAP_IS_UDP(ld) ) {
-                           err = ber_write( ber, ld->ld_options.ldo_peer,
-                               sizeof(struct sockaddr), 0);
+                               err = ber_write( ber, ld->ld_options.ldo_peer,
+                                       sizeof(struct sockaddr), 0);
                        }
                        if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
-                               LDAP_VERSION2) {
-                           char *dn = ld->ld_options.ldo_cldapdn;
-                           if (!dn) dn = "";
-                           err = ber_printf( ber, "{isti",  /* '}' */
-                               i, dn,
-                               LDAP_REQ_ABANDON, msgid );
+                               LDAP_VERSION2 )
+                       {
+                               char *dn = ld->ld_options.ldo_cldapdn;
+                               if (!dn) dn = "";
+                               err = ber_printf( ber, "{isti",  /* '}' */
+                                       i, dn,
+                                       LDAP_REQ_ABANDON, msgid );
                        } else
 #endif
                        {
-                           /* create a message to send */
-                           err = ber_printf( ber, "{iti",  /* '}' */
-                               i,
-                               LDAP_REQ_ABANDON, msgid );
+                               /* create a message to send */
+                               err = ber_printf( ber, "{iti",  /* '}' */
+                                       i,
+                                       LDAP_REQ_ABANDON, msgid );
                        }
 
                        if( err == -1 ) {
@@ -238,12 +239,13 @@ do_abandon(
                        } else {
                                /* send the message */
                                if ( lr != NULL ) {
+                                       assert( lr->lr_conn != NULL );
                                        sb = lr->lr_conn->lconn_sb;
                                } else {
                                        sb = ld->ld_sb;
                                }
 
-                               if ( ber_flush( sb, ber, 1 ) != 0 ) {
+                               if ( ber_flush2( sb, ber, LBER_FLUSH_FREE_ALWAYS ) != 0 ) {
                                        ld->ld_errno = LDAP_SERVER_DOWN;
                                        err = -1;
                                } else {
@@ -262,6 +264,12 @@ do_abandon(
                }
        }
 
+#ifdef LDAP_R_COMPILE
+       /* ld_abandoned is actually protected by the ld_res_mutex;
+        * give up the ld_req_mutex and get the other */
+       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+       ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
+#endif
        i = 0;
        if ( ld->ld_abandoned != NULL ) {
                for ( ; ld->ld_abandoned[i] != -1; i++ )
@@ -276,7 +284,7 @@ do_abandon(
        if ( ld->ld_abandoned == NULL ) {
                ld->ld_abandoned = old_abandon;
                ld->ld_errno = LDAP_NO_MEMORY;
-               return( ld->ld_errno );
+               goto done;
        }
 
        ld->ld_abandoned[i] = msgid;
@@ -286,5 +294,10 @@ do_abandon(
                ld->ld_errno = LDAP_SUCCESS;
        }
 
+done:;
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
+       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
        return( ld->ld_errno );
 }