]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/connection.c
Add trickle-sync for quick mode
[openldap] / servers / slapd / connection.c
index ce2c8f6e92c75fabdfa30c846a7fc29f4525c2ee..e4e2c9e28c7aa77db83da7d650b77774c44c825f 100644 (file)
@@ -359,14 +359,15 @@ static void connection_return( Connection *c )
        ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 }
 
-long connection_init(
+Connection * connection_init(
        ber_socket_t s,
        Listener *listener,
        const char* dnsname,
        const char* peername,
        int flags,
        slap_ssf_t ssf,
-       struct berval *authid )
+       struct berval *authid
+       LDAP_PF_LOCAL_SENDMSG_ARG(struct berval *peerbv))
 {
        unsigned long id;
        Connection *c;
@@ -379,13 +380,13 @@ long connection_init(
        assert( peername != NULL );
 
 #ifndef HAVE_TLS
-       assert( flags != CONN_IS_TLS );
+       assert( !( flags & CONN_IS_TLS ));
 #endif
 
        if( s == AC_SOCKET_INVALID ) {
                Debug( LDAP_DEBUG_ANY,
                        "connection_init: init of socket %ld invalid.\n", (long)s, 0, 0 );
-               return -1;
+               return NULL;
        }
 
        assert( s >= 0 );
@@ -442,7 +443,7 @@ long connection_init(
                        Debug( LDAP_DEBUG_ANY,
                                "connection_init(%d): connection table full "
                                "(%d/%d)\n", s, i, dtblsize);
-                       return -1;
+                       return NULL;
                }
        }
 #endif
@@ -525,14 +526,15 @@ long connection_init(
 
        c->c_listener = listener;
 
-       if ( flags == CONN_IS_CLIENT ) {
+       if ( flags & CONN_IS_CLIENT ) {
+               c->c_connid = 0;
                c->c_conn_state = SLAP_C_CLIENT;
                c->c_struct_state = SLAP_C_USED;
                c->c_close_reason = "?";                        /* should never be needed */
                ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
                ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 
-               return 0;
+               return c;
        }
 
        ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
@@ -559,7 +561,7 @@ long connection_init(
 
 #ifdef LDAP_CONNECTIONLESS
        c->c_is_udp = 0;
-       if( flags == CONN_IS_UDP ) {
+       if( flags & CONN_IS_UDP ) {
                c->c_is_udp = 1;
 #ifdef LDAP_DEBUG
                ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
@@ -570,7 +572,21 @@ long connection_init(
                ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_readahead,
                        LBER_SBIOD_LEVEL_PROVIDER, NULL );
        } else
+#endif /* LDAP_CONNECTIONLESS */
+#ifdef LDAP_PF_LOCAL
+       if ( flags & CONN_IS_IPC ) {
+#ifdef LDAP_DEBUG
+               ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
+                       LBER_SBIOD_LEVEL_PROVIDER, (void*)"ipc_" );
+#endif
+               ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_fd,
+                       LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
+#ifdef LDAP_PF_LOCAL_SENDMSG
+               if ( !BER_BVISEMPTY( peerbv ))
+                       ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_UNGET_BUF, peerbv );
 #endif
+       } else
+#endif /* LDAP_PF_LOCAL */
        {
 #ifdef LDAP_DEBUG
                ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
@@ -605,7 +621,7 @@ long connection_init(
        c->c_tls_ssf = 0;
 
 #ifdef HAVE_TLS
-       if ( flags == CONN_IS_TLS ) {
+       if ( flags & CONN_IS_TLS ) {
                c->c_is_tls = 1;
                c->c_needs_tls_accept = 1;
        } else {
@@ -622,7 +638,7 @@ long connection_init(
 
        backend_connection_init(c);
 
-       return id;
+       return c;
 }
 
 void connection2anonymous( Connection *c )
@@ -1111,7 +1127,7 @@ connection_operation( void *ctx, void *arg_v )
 #endif
        memsiz = SLAP_SLAB_SIZE;
 
-       memctx = slap_sl_mem_create( memsiz, SLAP_SLAB_STACK, ctx );
+       memctx = slap_sl_mem_create( memsiz, SLAP_SLAB_STACK, ctx, 1 );
        op->o_tmpmemctx = memctx;
        op->o_tmpmfuncs = &slap_sl_mfuncs;
        if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) {
@@ -1157,7 +1173,7 @@ operations_error:
 
        ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx_null );
 
-       LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
+       LDAP_STAILQ_REMOVE( &conn->c_ops, op, Operation, o_next);
        LDAP_STAILQ_NEXT(op, o_next) = NULL;
        slap_op_free( op );
        conn->c_n_ops_executing--;
@@ -1187,17 +1203,16 @@ int connection_client_setup(
        int rc;
        Connection *c;
 
-       rc = connection_init( s, (Listener *)&dummy_list, "", "",
-               CONN_IS_CLIENT, 0, NULL );
-       if ( rc < 0 ) return -1;
+       c = connection_init( s, (Listener *)&dummy_list, "", "",
+               CONN_IS_CLIENT, 0, NULL
+               LDAP_PF_LOCAL_SENDMSG_ARG(NULL));
+       if ( !c ) return -1;
 
-       c = connection_get( s );
        c->c_clientfunc = func;
        c->c_clientarg = arg;
 
        slapd_add_internal( s, 0 );
        slapd_set_read( s, 1 );
-       connection_return( c );
        return 0;
 }
 
@@ -1946,11 +1961,51 @@ int connection_write(ber_socket_t s)
        return 0;
 }
 
+#ifdef LDAP_SLAPI
+typedef struct conn_fake_extblock {
+       void *eb_conn;
+       void *eb_op;
+} conn_fake_extblock;
+
+static void
+connection_fake_destroy(
+       void *key,
+       void *data )
+{
+       Connection conn = {0};
+       Operation op = {0};
+       Opheader ohdr = {0};
+
+       conn_fake_extblock *eb = data;
+       
+       op.o_hdr = &ohdr;
+       op.o_hdr->oh_extensions = eb->eb_op;
+       conn.c_extensions = eb->eb_conn;
+       op.o_conn = &conn;
+       conn.c_connid = -1;
+       op.o_connid = -1;
+
+       ber_memfree_x( eb, NULL );
+       slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, &op );
+       slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, &conn );
+}
+#endif
+
 void
 connection_fake_init(
        Connection *conn,
        Operation *op,
        void *ctx )
+{
+       connection_fake_init2( conn, op, ctx, 1 );
+}
+
+void
+connection_fake_init2(
+       Connection *conn,
+       Operation *op,
+       void *ctx,
+       int newmem )
 {
        conn->c_connid = -1;
        conn->c_send_ldap_result = slap_send_ldap_result;
@@ -1964,7 +2019,8 @@ connection_fake_init(
        op->o_hdr = (Opheader *)(op+1);
        op->o_controls = (void **)(op->o_hdr+1);
        /* set memory context */
-       op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx);
+       op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx,
+               newmem );
        op->o_tmpmfuncs = &slap_sl_mfuncs;
        op->o_threadctx = ctx;
        op->o_tid = ldap_pvt_thread_pool_tid( ctx );
@@ -1974,12 +2030,23 @@ connection_fake_init(
        connection_init_log_prefix( op );
 
 #ifdef LDAP_SLAPI
-       /* FIXME: somebody needs to destroy these. Perhaps they should
-        * only be allocated on the slab.
-        */
        if ( slapi_plugins_used ) {
-               slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
-               slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
+               conn_fake_extblock *eb = NULL;
+
+               /* Use thread keys to make sure these eventually get cleaned up */
+               if ( ldap_pvt_thread_pool_getkey( ctx, connection_fake_init, &eb,
+                       NULL )) {
+                       eb = ch_malloc( sizeof( *eb ));
+                       slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
+                       slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
+                       eb->eb_conn = conn->c_extensions;
+                       eb->eb_op = op->o_hdr->oh_extensions;
+                       ldap_pvt_thread_pool_setkey( ctx, connection_fake_init, eb,
+                               connection_fake_destroy );
+               } else {
+                       conn->c_extensions = eb->eb_conn;
+                       op->o_hdr->oh_extensions = eb->eb_op;
+               }
        }
 #endif /* LDAP_SLAPI */