]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/connection.c
More for ITS#6045: clear o_callback as well.
[openldap] / servers / slapd / connection.c
index f20a0552b487ffd142a6989e9f52a6dbd0f38e69..6781d2a34f92d271c863ff4622c3495a85011cd2 100644 (file)
@@ -1,7 +1,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
@@ -218,9 +218,12 @@ int connections_shutdown(void)
  */
 int connections_timeout_idle(time_t now)
 {
-       int i = 0;
+       int i = 0, writers = 0;
        int connindex;
        Connection* c;
+       time_t old;
+
+       old = slapd_get_writetime();
 
        for( c = connection_first( &connindex );
                c != NULL;
@@ -240,9 +243,21 @@ int connections_timeout_idle(time_t now)
                        connection_closing( c, "idletimeout" );
                        connection_close( c );
                        i++;
+                       continue;
+               }
+               if ( c->c_writewaiter ) {
+                       writers = 1;
+                       if( difftime( c->c_activitytime+global_writetimeout, now) < 0 ) {
+                               /* close it */
+                               connection_closing( c, "writetimeout" );
+                               connection_close( c );
+                               i++;
+                       }
                }
        }
        connection_done( c );
+       if ( !writers )
+               slapd_clr_writetime( old );
 
        return i;
 }
@@ -761,8 +776,8 @@ void connection_closing( Connection *c, const char *why )
                connection_abandon( c );
 
                /* wake write blocked operations */
+               ldap_pvt_thread_mutex_lock( &c->c_write1_mutex );
                if ( c->c_writers > 0 ) {
-                       ldap_pvt_thread_mutex_lock( &c->c_write1_mutex );
                        c->c_writers = -c->c_writers;
                        ldap_pvt_thread_cond_broadcast( &c->c_write1_cv );
                        ldap_pvt_thread_mutex_unlock( &c->c_write1_mutex );
@@ -778,6 +793,7 @@ void connection_closing( Connection *c, const char *why )
                        }
                        ldap_pvt_thread_mutex_unlock( &c->c_write1_mutex );
                } else {
+                       ldap_pvt_thread_mutex_unlock( &c->c_write1_mutex );
                        slapd_clr_write( c->c_sd, 1 );
                }
 
@@ -1183,7 +1199,7 @@ void connection_client_stop(
 
        /* get (locked) connection */
        c = connection_get( s );
-       
+
        assert( c->c_conn_state == SLAP_C_CLIENT );
 
        c->c_listener = NULL;
@@ -1262,9 +1278,14 @@ connection_hangup( ber_socket_t s )
 
        c = connection_get( s );
        if ( c ) {
-               connection_closing( c, "connection lost" );
-               connection_close( c );
-               connection_return( c );
+               if ( c->c_conn_state == SLAP_C_CLIENT ) {
+                       connection_return( c );
+                       connection_read_activate( s );
+               } else {
+                       connection_closing( c, "connection lost" );
+                       connection_close( c );
+                       connection_return( c );
+               }
        }
 }
 
@@ -1853,7 +1874,9 @@ int connection_write(ber_socket_t s)
        Debug( LDAP_DEBUG_TRACE,
                "connection_write(%d): waking output for id=%lu\n",
                s, c->c_connid, 0 );
+       ldap_pvt_thread_mutex_lock( &c->c_write2_mutex );
        ldap_pvt_thread_cond_signal( &c->c_write2_cv );
+       ldap_pvt_thread_mutex_unlock( &c->c_write2_mutex );
 
        if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) ) {
                slapd_set_read( s, 1 );