]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/result.c
fix ITS#5959 fix
[openldap] / servers / slapd / result.c
index b5c6b90f5f3d5086c0ca1f93e39692d49acf4de1..0756260de04ab20c39dbb424b25379e2748c2ef1 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 The OpenLDAP Foundation.
+ * Copyright 1998-2009 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -144,6 +144,10 @@ static long send_ldap_ber(
 
        /* write only one pdu at a time - wait til it's our turn */
        ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
+       if ( connection_state_closing( conn )) {
+               ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
+               return 0;
+       }
        while ( conn->c_writers > 0 ) {
                ldap_pvt_thread_cond_wait( &conn->c_write1_cv, &conn->c_write1_mutex );
        }
@@ -156,17 +160,26 @@ static long send_ldap_ber(
        }
 
        conn->c_writers++;
-       ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
 
-       if ( closing )
+       if ( closing ) {
+               ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
                return 0;
+       }
 
        /* write the pdu */
        while( 1 ) {
                int err;
 
                /* lock the connection */ 
-               ldap_pvt_thread_mutex_lock( &conn->c_mutex );
+               if ( ldap_pvt_thread_mutex_trylock( &conn->c_mutex )) {
+                       ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
+                       ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
+                       if ( conn->c_writers < 0 ) {
+                               ret = 0;
+                               break;
+                       }
+                       continue;
+               }
 
                if ( ber_flush2( conn->c_sb, ber, LBER_FLUSH_FREE_NEVER ) == 0 ) {
                        ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
@@ -186,12 +199,12 @@ static long send_ldap_ber(
                    err, sock_errstr(err), 0 );
 
                if ( err != EWOULDBLOCK && err != EAGAIN ) {
+                       conn->c_writers--;
+                       ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
                        connection_closing( conn, "connection lost on write" );
 
                        ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
-
-                       ret = -1;
-                       break;
+                       return -1;
                }
 
                /* wait for socket to be write-ready */
@@ -199,20 +212,18 @@ static long send_ldap_ber(
                conn->c_writewaiter = 1;
                slapd_set_write( conn->c_sd, 1 );
 
+               ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
                ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
                ldap_pvt_thread_cond_wait( &conn->c_write2_cv, &conn->c_write2_mutex );
                conn->c_writewaiter = 0;
                ldap_pvt_thread_mutex_unlock( &conn->c_write2_mutex );
                ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
-               closing = ( conn->c_writers < 0 );
-               ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
-               if ( closing ) {
+               if ( conn->c_writers < 0 ) {
                        ret = 0;
                        break;
                }
        }
 
-       ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
        if ( conn->c_writers < 0 ) {
                conn->c_writers++;
                if ( !conn->c_writers )
@@ -1645,9 +1656,9 @@ slap_attr_flags( AttributeName *an )
                flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
 
        } else {
-               flags |= an_find( an, &AllOper )
+               flags |= an_find( an, slap_bv_all_operational_attrs )
                        ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
-               flags |= an_find( an, &AllUser )
+               flags |= an_find( an, slap_bv_all_user_attrs )
                        ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;
        }