]> git.sur5r.net Git - openldap/commitdiff
Implement "quick" shutdown (similiar in behavior to shutdown
authorKurt Zeilenga <kurt@openldap.org>
Fri, 23 Apr 1999 22:50:28 +0000 (22:50 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 23 Apr 1999 22:50:28 +0000 (22:50 +0000)
prior to connection management changes).  No "normal" (wait
for pending operations to complete) shutdown mode (yet).
Changes:
 Add connections_destroy() implementation to connections.c.
 Move connections_init() call to slap_daemon().
 Add connections_destroy() call to slap_daemon().
 Add connections_shutdown() implementation to connections.c.
calls connection_closing()/connection_close() for each
"in use" connection.
 Add connections_shutdown() call to slap_daemon_task().

servers/slapd/connection.c
servers/slapd/daemon.c
servers/slapd/proto-slap.h

index 7031c199ccf67cf8acbfbec2a6bcdbec01272608..3c65f478bc341026b87097cf58293e8596b97fac 100644 (file)
@@ -36,6 +36,7 @@ void slapd_remove(int s);
 static Connection* connection_get( int s );
 
 static int connection_input( Connection *c );
+static void connection_close( Connection *c );
 
 static int connection_op_activate( Connection *conn, Operation *op );
 static int connection_resched( Connection *conn );
@@ -54,7 +55,7 @@ int connections_init(void)
 
        assert( connections == NULL );
 
-       if( connections != NULL) { /* probably should assert this */
+       if( connections != NULL) {
                Debug( LDAP_DEBUG_ANY, "connections_init: already initialized.\n",
                        0, 0, 0 );
                return -1;
@@ -83,6 +84,59 @@ int connections_init(void)
        return 0;
 }
 
+/*
+ * Destroy connection management infrastructure.
+ */
+int connections_destroy(void)
+{
+       int i;
+
+       /* should check return of every call */
+
+       if( connections == NULL) {
+               Debug( LDAP_DEBUG_ANY, "connections_destroy: nothing to destroy.\n",
+                       0, 0, 0 );
+               return -1;
+       }
+
+       for ( i = 0; i < dtblsize; i++ ) {
+               ldap_pvt_thread_mutex_destroy( &connections[i].c_mutex );
+               ldap_pvt_thread_mutex_destroy( &connections[i].c_write_mutex );
+               ldap_pvt_thread_cond_destroy( &connections[i].c_write_cv );
+
+               free( &connections[i] );
+       }
+
+       free( connections );
+       connections = NULL;
+
+       ldap_pvt_thread_mutex_destroy( &connections_mutex );
+       return 0;
+}
+
+/*
+ * shutdown all connections
+ */
+int connections_shutdown(void)
+{
+       int i;
+
+       ldap_pvt_thread_mutex_lock( &connections_mutex );
+
+       for ( i = 0; i < dtblsize; i++ ) {
+               if( connections[i].c_struct_state != SLAP_C_USED ) {
+                       continue;
+               }
+
+               ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
+               connection_closing( &connections[i] );
+               connection_close( &connections[i] );
+               ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
+       }
+
+       ldap_pvt_thread_mutex_unlock( &connections_mutex );
+}
+
 static Connection* connection_get( int s )
 {
        Connection *c = NULL;
@@ -310,11 +364,17 @@ connection_destroy( Connection *c )
 
 int connection_state_closing( Connection *c )
 {
+       int state;
        assert( c != NULL );
        assert( c->c_struct_state == SLAP_C_USED );
-       assert( c->c_conn_state != SLAP_C_INVALID );
 
-       return c->c_conn_state == SLAP_C_CLOSING;
+    ldap_pvt_thread_mutex_lock( &c->c_mutex );
+       state = c->c_conn_state;
+    ldap_pvt_thread_mutex_unlock( &c->c_mutex );
+
+       assert( state != SLAP_C_INVALID );
+
+       return state == SLAP_C_CLOSING;
 }
 
 void connection_closing( Connection *c )
index 1f20c881a4fc6bc7e9df368a6e8f71919f9515ba..05a38dbd9c5d67adf18747cc5dee31b93b8c55a5 100644 (file)
@@ -232,8 +232,6 @@ slapd_daemon_task(
 
        slapd_listener=1;
 
-       connections_init();
-
        ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
        FD_ZERO( &slap_daemon.sd_readers );
        FD_ZERO( &slap_daemon.sd_writers );
@@ -582,6 +580,9 @@ slapd_daemon_task(
                tcp_close( tcps );
        }
 
+       /* we only implement "quick" shutdown */
+       connections_shutdown();
+
        ldap_pvt_thread_mutex_lock( &active_threads_mutex );
        Debug( LDAP_DEBUG_ANY,
            "slapd shutdown: waiting for %d threads to terminate\n",
@@ -602,6 +603,8 @@ int slapd_daemon( int inetd, int tcps )
        args[0] = inetd;
        args[1] = tcps;
 
+       connections_init();
+
 #define SLAPD_LISTENER_THREAD 1
 #if SLAPD_LISTENER_THREAD
        /* listener as a separate THREAD */
@@ -622,6 +625,7 @@ int slapd_daemon( int inetd, int tcps )
        slapd_daemon_task( args );
 #endif
 
+       connections_destroy();
        return 0;
 }
 
index d35ab85802ffc7fb24877fd6494e97756a42806d..e31aff18a3a4b212abe4d0cd0a69ba7456c21c23 100644 (file)
@@ -114,6 +114,8 @@ int read_config LDAP_P(( char *fname ));
  * connection.c
  */
 int connections_init LDAP_P((void));
+int connections_shutdown LDAP_P((void));
+int connections_destroy LDAP_P((void));
 
 long connection_init LDAP_P((
        int s,