]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/connection.c
debug messages incorrectly said "add" instead of "remove".
[openldap] / servers / slapd / connection.c
index 5c3ebdf708f7307d78562dee2c30ceaf4f4e567d..36fca0b705356a6b268055176c6eb5dee9ad076e 100644 (file)
@@ -1,25 +1,14 @@
-#include <stdio.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <signal.h>
 #include "portable.h"
-#include "slap.h"
 
-extern Operation       *op_add();
-extern int             active_threads;
-extern pthread_mutex_t active_threads_mutex;
-extern pthread_mutex_t new_conn_mutex;
-extern long            ops_initiated;
-extern long            ops_completed;
-extern pthread_mutex_t ops_mutex;
-extern pthread_t       listener_tid;
-#ifndef SYSERRLIST_IN_STDIO
-extern int             sys_nerr;
-extern char            *sys_errlist[];
-#endif
+#include <stdio.h>
+
+#include <ac/errno.h>
+#include <ac/signal.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#include "slap.h"
 
 struct co_arg {
        Connection      *co_conn;
@@ -32,9 +21,10 @@ struct co_arg {
  * calls the appropriate stub to handle it.
  */
 
-static void
-connection_operation( struct co_arg *arg )
+static void *
+connection_operation( void *arg_v )
 {
+       struct co_arg   *arg = arg_v;
        unsigned long   len;
 
        pthread_mutex_lock( &arg->co_conn->c_opsmutex );
@@ -50,7 +40,7 @@ connection_operation( struct co_arg *arg )
                do_bind( arg->co_conn, arg->co_op );
                break;
 
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
        case LDAP_REQ_UNBIND_30:
 #endif
        case LDAP_REQ_UNBIND:
@@ -61,7 +51,7 @@ connection_operation( struct co_arg *arg )
                do_add( arg->co_conn, arg->co_op );
                break;
 
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
        case LDAP_REQ_DELETE_30:
 #endif
        case LDAP_REQ_DELETE:
@@ -84,7 +74,7 @@ connection_operation( struct co_arg *arg )
                do_search( arg->co_conn, arg->co_op );
                break;
 
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
        case LDAP_REQ_ABANDON_30:
 #endif
        case LDAP_REQ_ABANDON:
@@ -92,7 +82,7 @@ connection_operation( struct co_arg *arg )
                break;
 
        default:
-               Debug( LDAP_DEBUG_ANY, "unknown request 0x%x\n",
+               Debug( LDAP_DEBUG_ANY, "unknown request 0x%lx\n",
                    arg->co_op->o_tag, 0, 0 );
                break;
        }
@@ -111,6 +101,7 @@ connection_operation( struct co_arg *arg )
        pthread_mutex_lock( &active_threads_mutex );
        active_threads--;
        pthread_mutex_unlock( &active_threads_mutex );
+       return NULL;
 }
 
 void
@@ -138,7 +129,7 @@ connection_activity(
                    "ber_get_next on fd %d failed errno %d (%s)\n",
                    conn->c_sb.sb_sd, errno, errno > -1 && errno < sys_nerr ?
                    sys_errlist[errno] : "unknown" );
-               Debug( LDAP_DEBUG_TRACE, "*** got %d of %d so far\n",
+               Debug( LDAP_DEBUG_TRACE, "*** got %d of %lu so far\n",
                    conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf,
                    conn->c_currentber->ber_len, 0 );
 
@@ -157,7 +148,7 @@ connection_activity(
 
        if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
                /* log, close and send error */
-               Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%x\n", tag, 0,
+               Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
                    0 );
                ber_free( ber, 1 );
 
@@ -167,7 +158,7 @@ connection_activity(
 
        if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
                /* log, close and send error */
-               Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%x\n", tag, 0,
+               Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
                    0 );
                ber_free( ber, 1 );
 
@@ -175,7 +166,7 @@ connection_activity(
                return;
        }
 
-#ifdef COMPAT30
+#ifdef LDAP_COMPAT30
        if ( conn->c_version == 30 ) {
                (void) ber_skip_tag( ber, &len );
        }
@@ -203,13 +194,30 @@ connection_activity(
 
        pthread_attr_init( &attr );
        pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
+#if !defined(HAVE_PTHREADS_D4)
+       /* POSIX_THREADS or compatible
+        * This is a draft 10 or standard pthreads implementation
+        */
+       if ( pthread_create( &arg->co_op->o_tid, &attr,
+           connection_operation, (void *) arg ) != 0 ) {
+               Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
+       } else {
+               pthread_mutex_lock( &active_threads_mutex );
+               active_threads++;
+               pthread_mutex_unlock( &active_threads_mutex );
+       }
+#else  /* pthread draft4  */
+       /*
+        * This is a draft 4 or earlier pthreads implementation
+        */
        if ( pthread_create( &arg->co_op->o_tid, attr,
-           (void *) connection_operation, (void *) arg ) != 0 ) {
+           connection_operation, (void *) arg ) != 0 ) {
                Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
        } else {
                pthread_mutex_lock( &active_threads_mutex );
                active_threads++;
                pthread_mutex_unlock( &active_threads_mutex );
        }
+#endif /* pthread draft4 */
        pthread_attr_destroy( &attr );
 }