13 /* we need LBER internals */
14 #include "../../libraries/liblber/lber-int.h"
16 /* protected by connections_mutex */
17 static ldap_pvt_thread_mutex_t connections_mutex;
18 static Connection *connections = NULL;
19 static unsigned long conn_nextid = 0;
21 /* structure state (protected by connections_mutex) */
22 #define SLAP_C_UNINITIALIZED 0x00 /* MUST BE ZERO (0) */
23 #define SLAP_C_UNUSED 0x01
24 #define SLAP_C_USED 0x02
26 /* connection state (protected by c_mutex ) */
27 #define SLAP_C_INVALID 0x00 /* MUST BE ZERO (0) */
28 #define SLAP_C_INACTIVE 0x01 /* zero threads */
29 #define SLAP_C_ACTIVE 0x02 /* one or more threads */
30 #define SLAP_C_BINDING 0x03 /* binding */
31 #define SLAP_C_CLOSING 0x04 /* closing */
33 char* connection_state2str( int state ) {
35 case SLAP_C_INVALID: return "!";
36 case SLAP_C_INACTIVE: return "|";
37 case SLAP_C_ACTIVE: return "";
38 case SLAP_C_BINDING: return "B";
39 case SLAP_C_CLOSING: return "C";
45 static Connection* connection_get( ber_socket_t s );
47 static int connection_input( Connection *c );
48 static void connection_close( Connection *c );
50 static int connection_op_activate( Connection *conn, Operation *op );
51 static int connection_resched( Connection *conn );
52 static void connection_abandon( Connection *conn );
53 static void connection_destroy( Connection *c );
61 * Initialize connection management infrastructure.
63 int connections_init(void)
65 assert( connections == NULL );
67 if( connections != NULL) {
68 Debug( LDAP_DEBUG_ANY, "connections_init: already initialized.\n",
73 /* should check return of every call */
74 ldap_pvt_thread_mutex_init( &connections_mutex );
76 connections = (Connection *) calloc( dtblsize, sizeof(Connection) );
78 if( connections == NULL ) {
79 Debug( LDAP_DEBUG_ANY,
80 "connections_init: allocation (%d*%ld) of connection array failed.\n",
81 dtblsize, (long) sizeof(Connection), 0 );
85 assert( connections[0].c_struct_state == SLAP_C_UNINITIALIZED );
86 assert( connections[dtblsize-1].c_struct_state == SLAP_C_UNINITIALIZED );
89 * per entry initialization of the Connection array initialization
90 * will be done by connection_init()
97 * Destroy connection management infrastructure.
99 int connections_destroy(void)
103 /* should check return of every call */
105 if( connections == NULL) {
106 Debug( LDAP_DEBUG_ANY, "connections_destroy: nothing to destroy.\n",
111 for ( i = 0; i < dtblsize; i++ ) {
112 if( connections[i].c_struct_state != SLAP_C_UNINITIALIZED ) {
113 ldap_pvt_thread_mutex_destroy( &connections[i].c_mutex );
114 ldap_pvt_thread_mutex_destroy( &connections[i].c_write_mutex );
115 ldap_pvt_thread_cond_destroy( &connections[i].c_write_cv );
122 ldap_pvt_thread_mutex_destroy( &connections_mutex );
127 * shutdown all connections
129 int connections_shutdown(void)
133 ldap_pvt_thread_mutex_lock( &connections_mutex );
135 for ( i = 0; i < dtblsize; i++ ) {
136 if( connections[i].c_struct_state != SLAP_C_USED ) {
140 ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
142 /* connections_mutex and c_mutex are locked */
143 connection_closing( &connections[i] );
144 connection_close( &connections[i] );
146 ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
149 ldap_pvt_thread_mutex_unlock( &connections_mutex );
155 * Timeout idle connections.
157 int connections_timeout_idle(time_t now)
163 ldap_pvt_thread_mutex_lock( &connections_mutex );
165 for( c = connection_first( &connindex );
167 c = connection_next( c, &connindex ) )
169 if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) {
171 connection_closing( c );
172 connection_close( c );
176 connection_done( c );
178 ldap_pvt_thread_mutex_unlock( &connections_mutex );
183 static Connection* connection_get( ber_socket_t s )
185 /* connections_mutex should be locked by caller */
189 Debug( LDAP_DEBUG_ARGS,
190 "connection_get(%ld)\n",
193 assert( connections != NULL );
195 if(s == AC_SOCKET_INVALID) {
202 assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
209 for(i=0; i<dtblsize; i++) {
210 if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
211 assert( connections[i].c_conn_state == SLAP_C_INVALID );
212 assert( connections[i].c_sb == 0 );
216 if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
217 assert( connections[i].c_conn_state == SLAP_C_INVALID );
218 assert( !ber_pvt_sb_in_use( connections[i].c_sb ) );
222 /* state can actually change from used -> unused by resched,
223 * so don't assert details here.
226 if( ber_pvt_sb_get_desc( connections[i].c_sb ) == s ) {
235 ldap_pvt_thread_mutex_lock( &c->c_mutex );
237 if( c->c_struct_state != SLAP_C_USED ) {
238 /* connection must have been closed due to resched */
240 assert( c->c_conn_state == SLAP_C_INVALID );
241 assert( !ber_pvt_sb_in_use( c->c_sb ) );
243 Debug( LDAP_DEBUG_TRACE,
244 "connection_get(%d): connection not used.\n",
247 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
251 Debug( LDAP_DEBUG_TRACE,
252 "connection_get(%d): got connid=%ld\n",
257 assert( c->c_struct_state == SLAP_C_USED );
258 assert( c->c_conn_state != SLAP_C_INVALID );
259 assert( ber_pvt_sb_in_use( c->c_sb ) );
261 c->c_activitytime = slap_get_time();
267 static void connection_return( Connection *c )
269 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
272 long connection_init(
280 assert( connections != NULL );
286 if( s == AC_SOCKET_INVALID ) {
287 Debug( LDAP_DEBUG_ANY,
288 "connection_init(%ld): invalid.\n",
295 assert( s < dtblsize );
298 ldap_pvt_thread_mutex_lock( &connections_mutex );
309 for( i=0; i < dtblsize; i++) {
310 if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
311 assert( connections[i].c_sb == 0 );
316 if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
317 assert( !ber_pvt_sb_in_use( connections[i].c_sb ));
322 assert( connections[i].c_struct_state == SLAP_C_USED );
323 assert( connections[i].c_conn_state != SLAP_C_INVALID );
324 assert( ber_pvt_sb_in_use( connections[i].c_sb ));
328 Debug( LDAP_DEBUG_ANY,
329 "connection_init(%d): connection table full (%d/%d).\n",
331 ldap_pvt_thread_mutex_unlock( &connections_mutex );
338 assert( c->c_struct_state != SLAP_C_USED );
339 assert( c->c_conn_state == SLAP_C_INVALID );
341 if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
344 c->c_client_name = NULL;
345 c->c_client_addr = NULL;
347 c->c_pending_ops = NULL;
348 c->c_authmech = NULL;
349 c->c_authstate = NULL;
351 c->c_sb = ber_sockbuf_alloc( );
353 /* should check status of thread calls */
354 ldap_pvt_thread_mutex_init( &c->c_mutex );
355 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
356 ldap_pvt_thread_cond_init( &c->c_write_cv );
358 c->c_struct_state = SLAP_C_UNUSED;
361 ldap_pvt_thread_mutex_lock( &c->c_mutex );
363 assert( c->c_struct_state == SLAP_C_UNUSED );
364 assert( c->c_dn == NULL );
365 assert( c->c_cdn == NULL );
366 assert( c->c_client_name == NULL );
367 assert( c->c_client_addr == NULL );
368 assert( c->c_ops == NULL );
369 assert( c->c_pending_ops == NULL );
370 assert( c->c_authmech == NULL );
371 assert( c->c_authstate == NULL );
373 c->c_client_name = ch_strdup( name == NULL ? "" : name );
374 c->c_client_addr = ch_strdup( addr );
376 c->c_n_ops_received = 0;
377 c->c_n_ops_executing = 0;
378 c->c_n_ops_pending = 0;
379 c->c_n_ops_completed = 0;
385 c->c_activitytime = c->c_starttime = slap_get_time();
387 ber_pvt_sb_set_desc( c->c_sb, s );
388 ber_pvt_sb_set_io( c->c_sb, &ber_pvt_sb_io_tcp, NULL );
390 if( ber_pvt_sb_set_nonblock( c->c_sb, 1 ) < 0 ) {
391 Debug( LDAP_DEBUG_ANY,
392 "connection_init(%d, %s, %s): set nonblocking failed\n",
393 s, c->c_client_name, c->c_client_addr);
396 id = c->c_connid = conn_nextid++;
398 c->c_conn_state = SLAP_C_INACTIVE;
399 c->c_struct_state = SLAP_C_USED;
404 c->c_needs_tls_accept = 1;
408 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
409 ldap_pvt_thread_mutex_unlock( &connections_mutex );
411 backend_connection_init(c);
417 connection_destroy( Connection *c )
419 /* note: connections_mutex should be locked by caller */
421 assert( connections != NULL );
423 assert( c->c_struct_state != SLAP_C_UNUSED );
424 assert( c->c_conn_state != SLAP_C_INVALID );
425 assert( c->c_ops == NULL );
427 backend_connection_destroy(c);
432 c->c_activitytime = c->c_starttime = 0;
434 if(c->c_dn != NULL) {
438 if(c->c_cdn != NULL) {
442 if(c->c_client_name != NULL) {
443 free(c->c_client_name);
444 c->c_client_name = NULL;
446 if(c->c_client_addr != NULL) {
447 free(c->c_client_addr);
448 c->c_client_addr = NULL;
450 if(c->c_authmech != NULL ) {
452 c->c_authmech = NULL;
454 if(c->c_authstate != NULL ) {
455 free(c->c_authstate);
456 c->c_authstate = NULL;
459 if ( ber_pvt_sb_in_use(c->c_sb) ) {
460 int sd = ber_pvt_sb_get_desc(c->c_sb);
462 slapd_remove( sd, 0 );
463 ber_pvt_sb_close( c->c_sb );
465 Statslog( LDAP_DEBUG_STATS,
466 "conn=%d fd=%d closed.\n",
467 c->c_connid, sd, 0, 0, 0 );
470 ber_pvt_sb_destroy( c->c_sb );
472 c->c_conn_state = SLAP_C_INVALID;
473 c->c_struct_state = SLAP_C_UNUSED;
476 int connection_state_closing( Connection *c )
478 /* c_mutex must be locked by caller */
482 assert( c->c_struct_state == SLAP_C_USED );
484 state = c->c_conn_state;
486 assert( state != SLAP_C_INVALID );
488 return state == SLAP_C_CLOSING;
491 static void connection_abandon( Connection *c )
493 /* c_mutex must be locked by caller */
497 for( o = c->c_ops; o != NULL; o = o->o_next ) {
498 ldap_pvt_thread_mutex_lock( &o->o_abandonmutex );
500 ldap_pvt_thread_mutex_unlock( &o->o_abandonmutex );
503 /* remove pending operations */
504 for( o = slap_op_pop( &c->c_pending_ops );
506 o = slap_op_pop( &c->c_pending_ops ) )
512 void connection_closing( Connection *c )
514 assert( connections != NULL );
516 assert( c->c_struct_state == SLAP_C_USED );
517 assert( c->c_conn_state != SLAP_C_INVALID );
519 /* c_mutex must be locked by caller */
521 if( c->c_conn_state != SLAP_C_CLOSING ) {
523 Debug( LDAP_DEBUG_TRACE,
524 "connection_closing: readying conn=%ld sd=%d for close.\n",
525 c->c_connid, ber_pvt_sb_get_desc( c->c_sb ), 0 );
527 /* update state to closing */
528 c->c_conn_state = SLAP_C_CLOSING;
530 /* don't listen on this port anymore */
531 slapd_clr_read( ber_pvt_sb_get_desc( c->c_sb ), 1 );
533 /* shutdown I/O -- not yet implemented */
535 /* abandon active operations */
536 connection_abandon( c );
538 /* wake write blocked operations */
539 slapd_clr_write( ber_pvt_sb_get_desc(c->c_sb), 1 );
540 ldap_pvt_thread_cond_signal( &c->c_write_cv );
544 static void connection_close( Connection *c )
546 assert( connections != NULL );
548 assert( c->c_struct_state == SLAP_C_USED );
549 assert( c->c_conn_state == SLAP_C_CLOSING );
551 /* note: connections_mutex and c_mutex should be locked by caller */
553 if( c->c_ops != NULL ) {
554 Debug( LDAP_DEBUG_TRACE,
555 "connection_close: deferring conn=%ld sd=%d.\n",
556 c->c_connid, ber_pvt_sb_get_desc( c->c_sb ), 0 );
561 Debug( LDAP_DEBUG_TRACE, "connection_close: conn=%ld sd=%d.\n",
562 c->c_connid, ber_pvt_sb_get_desc( c->c_sb ), 0 );
564 connection_destroy( c );
567 unsigned long connections_nextid(void)
570 assert( connections != NULL );
572 ldap_pvt_thread_mutex_lock( &connections_mutex );
576 ldap_pvt_thread_mutex_unlock( &connections_mutex );
581 Connection* connection_first( ber_socket_t *index )
583 assert( connections != NULL );
584 assert( index != NULL );
586 ldap_pvt_thread_mutex_lock( &connections_mutex );
590 return connection_next(NULL, index);
593 Connection* connection_next( Connection *c, ber_socket_t *index )
595 assert( connections != NULL );
596 assert( index != NULL );
597 assert( *index <= dtblsize );
600 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
605 for(; *index < dtblsize; (*index)++) {
606 if( connections[*index].c_struct_state == SLAP_C_UNINITIALIZED ) {
607 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
615 if( connections[*index].c_struct_state == SLAP_C_USED ) {
616 assert( connections[*index].c_conn_state != SLAP_C_INVALID );
617 c = &connections[(*index)++];
621 assert( connections[*index].c_struct_state == SLAP_C_UNUSED );
622 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
626 ldap_pvt_thread_mutex_lock( &c->c_mutex );
632 void connection_done( Connection *c )
634 assert( connections != NULL );
637 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
640 ldap_pvt_thread_mutex_unlock( &connections_mutex );
644 * connection_activity - handle the request operation op on connection
645 * conn. This routine figures out what kind of operation it is and
646 * calls the appropriate stub to handle it.
650 connection_operation( void *arg_v )
653 struct co_arg *arg = arg_v;
654 ber_tag_t tag = arg->co_op->o_tag;
655 Connection *conn = arg->co_conn;
657 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
659 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
663 rc = do_bind( conn, arg->co_op );
666 case LDAP_REQ_UNBIND:
667 rc = do_unbind( conn, arg->co_op );
671 rc = do_add( conn, arg->co_op );
674 case LDAP_REQ_DELETE:
675 rc = do_delete( conn, arg->co_op );
678 case LDAP_REQ_MODRDN:
679 rc = do_modrdn( conn, arg->co_op );
682 case LDAP_REQ_MODIFY:
683 rc = do_modify( conn, arg->co_op );
686 case LDAP_REQ_COMPARE:
687 rc = do_compare( conn, arg->co_op );
690 case LDAP_REQ_SEARCH:
691 rc = do_search( conn, arg->co_op );
694 case LDAP_REQ_ABANDON:
695 rc = do_abandon( conn, arg->co_op );
698 case LDAP_REQ_EXTENDED:
699 rc = do_extended( conn, arg->co_op );
703 Debug( LDAP_DEBUG_ANY, "unknown LDAP request 0x%lx\n",
705 arg->co_op->o_tag = LBER_ERROR;
706 send_ldap_disconnect( conn, arg->co_op,
707 LDAP_PROTOCOL_ERROR, "unknown LDAP request" );
712 if( rc == -1 ) tag = LBER_ERROR;
714 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
716 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
718 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
720 conn->c_n_ops_executing--;
721 conn->c_n_ops_completed++;
723 slap_op_remove( &conn->c_ops, arg->co_op );
724 slap_op_free( arg->co_op );
727 free( (char *) arg );
732 case LDAP_REQ_UNBIND:
733 /* c_mutex is locked */
734 connection_closing( conn );
738 if( conn->c_conn_state == SLAP_C_BINDING) {
739 conn->c_conn_state = SLAP_C_ACTIVE;
741 conn->c_bind_in_progress = ( rc == LDAP_SASL_BIND_IN_PROGRESS );
744 ldap_pvt_thread_mutex_lock( &active_threads_mutex );
746 if( active_threads < 1 ) {
747 ldap_pvt_thread_cond_signal(&active_threads_cond);
749 ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
751 connection_resched( conn );
753 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
758 int connection_read(ber_socket_t s)
762 assert( connections != NULL );
764 ldap_pvt_thread_mutex_lock( &connections_mutex );
766 /* get (locked) connection */
767 c = connection_get( s );
770 Debug( LDAP_DEBUG_ANY,
771 "connection_read(%ld): no connection!\n",
776 ldap_pvt_thread_mutex_unlock( &connections_mutex );
782 if( c->c_conn_state == SLAP_C_CLOSING ) {
783 Debug( LDAP_DEBUG_TRACE,
784 "connection_read(%d): closing, ignoring input for id=%ld\n",
787 connection_return( c );
788 ldap_pvt_thread_mutex_unlock( &connections_mutex );
792 Debug( LDAP_DEBUG_TRACE,
793 "connection_read(%d): checking for input on id=%ld\n",
797 if ( c->c_is_tls && c->c_needs_tls_accept ) {
798 rc = ldap_pvt_tls_accept( c->c_sb, NULL );
800 Debug( LDAP_DEBUG_TRACE,
801 "connection_read(%d): TLS accept error error=%d id=%ld, closing.\n",
802 s, rc, c->c_connid );
804 c->c_needs_tls_accept = 0;
805 /* connections_mutex and c_mutex are locked */
806 connection_closing( c );
807 connection_close( c );
808 } else if ( rc == 0 ) {
809 c->c_needs_tls_accept = 0;
811 connection_return( c );
812 ldap_pvt_thread_mutex_unlock( &connections_mutex );
817 #define CONNECTION_INPUT_LOOP 1
819 #ifdef DATA_READY_LOOP
820 while(rc >= 0 && ber_pvt_sb_data_ready(&c->c_sb))
821 #elif CONNECTION_INPUT_LOOP
825 rc = connection_input( c );
829 Debug( LDAP_DEBUG_TRACE,
830 "connection_read(%d): input error=%d id=%ld, closing.\n",
831 s, rc, c->c_connid );
833 /* connections_mutex and c_mutex are locked */
834 connection_closing( c );
835 connection_close( c );
838 if ( ber_pvt_sb_needs_read( c->c_sb ) )
839 slapd_set_read( s, 1 );
840 if ( ber_pvt_sb_needs_write( c->c_sb ) )
841 slapd_set_write( s, 1 );
842 connection_return( c );
843 ldap_pvt_thread_mutex_unlock( &connections_mutex );
858 if ( conn->c_currentber == NULL && (conn->c_currentber = ber_alloc())
860 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
865 if ( (tag = ber_get_next( conn->c_sb, &len, conn->c_currentber ))
866 != LDAP_TAG_MESSAGE )
870 Debug( LDAP_DEBUG_TRACE,
871 "ber_get_next on fd %d failed errno %d (%s)\n",
872 ber_pvt_sb_get_desc( conn->c_sb ), err,
873 err > -1 && err < sys_nerr ? sys_errlist[err] : "unknown" );
874 Debug( LDAP_DEBUG_TRACE,
875 "\t*** got %ld of %lu so far\n",
876 (long)(conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf),
877 conn->c_currentber->ber_len, 0 );
879 if ( err != EWOULDBLOCK && err != EAGAIN ) {
880 /* log, close and send error */
881 ber_free( conn->c_currentber, 1 );
882 conn->c_currentber = NULL;
889 ber = conn->c_currentber;
890 conn->c_currentber = NULL;
892 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
893 /* log, close and send error */
894 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
900 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
901 /* log, close and send error */
902 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
909 if(tag == LDAP_REQ_BIND) {
910 /* immediately abandon all exiting operations upon BIND */
911 connection_abandon( conn );
914 op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++ );
916 if ( conn->c_conn_state == SLAP_C_BINDING
917 || conn->c_conn_state == SLAP_C_CLOSING )
919 Debug( LDAP_DEBUG_ANY, "deferring operation\n", 0, 0, 0 );
920 conn->c_n_ops_pending++;
921 slap_op_add( &conn->c_pending_ops, op );
924 conn->c_n_ops_executing++;
925 connection_op_activate( conn, op );
929 if ( conn->c_struct_state != SLAP_C_USED ) {
930 /* connection must have got closed underneath us */
934 assert( conn->c_struct_state == SLAP_C_USED );
940 connection_resched( Connection *conn )
944 if( conn->c_conn_state == SLAP_C_CLOSING ) {
945 Debug( LDAP_DEBUG_TRACE,
946 "connection_resched: attempting closing conn=%ld sd=%d.\n",
947 conn->c_connid, ber_pvt_sb_get_desc( conn->c_sb ), 0 );
949 connection_close( conn );
953 if( conn->c_conn_state != SLAP_C_ACTIVE ) {
954 /* other states need different handling */
958 for( op = slap_op_pop( &conn->c_pending_ops );
960 op = slap_op_pop( &conn->c_pending_ops ) )
962 /* pending operations should not be marked for abandonment */
963 assert(!op->o_abandon);
965 conn->c_n_ops_pending--;
966 conn->c_n_ops_executing++;
968 connection_op_activate( conn, op );
970 if ( conn->c_conn_state == SLAP_C_BINDING ) {
977 static int connection_op_activate( Connection *conn, Operation *op )
982 ber_tag_t tag = op->o_tag;
984 if(tag == LDAP_REQ_BIND) {
985 conn->c_conn_state = SLAP_C_BINDING;
988 if ( conn->c_dn != NULL ) {
989 tmpdn = ch_strdup( conn->c_dn );
994 arg = (struct co_arg *) ch_malloc( sizeof(struct co_arg) );
998 arg->co_op->o_bind_in_progress = conn->c_bind_in_progress;
1000 arg->co_op->o_dn = ch_strdup( tmpdn != NULL ? tmpdn : "" );
1001 arg->co_op->o_ndn = dn_normalize_case( ch_strdup( arg->co_op->o_dn ) );
1003 arg->co_op->o_protocol = conn->c_protocol;
1004 arg->co_op->o_connid = conn->c_connid;
1006 arg->co_op->o_authtype = conn->c_authtype;
1007 arg->co_op->o_authmech = conn->c_authmech != NULL
1008 ? ch_strdup( conn->c_authmech ) : NULL;
1010 slap_op_add( &conn->c_ops, arg->co_op );
1012 if( tmpdn != NULL ) {
1016 ldap_pvt_thread_mutex_lock( &active_threads_mutex );
1018 ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
1020 status = ldap_pvt_thread_create( &arg->co_op->o_tid, 1,
1021 connection_operation, (void *) arg );
1023 if ( status != 0 ) {
1024 Debug( LDAP_DEBUG_ANY,
1025 "ldap_pvt_thread_create failed (%d)\n", status, 0, 0 );
1027 /* should move op to pending list */
1033 int connection_write(ber_socket_t s)
1036 assert( connections != NULL );
1038 ldap_pvt_thread_mutex_lock( &connections_mutex );
1040 c = connection_get( s );
1042 slapd_clr_write( s, 0);
1045 Debug( LDAP_DEBUG_ANY,
1046 "connection_write(%ld): no connection!\n",
1049 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1055 Debug( LDAP_DEBUG_TRACE,
1056 "connection_write(%d): waking output for id=%ld\n",
1057 s, c->c_connid, 0 );
1059 ldap_pvt_thread_cond_signal( &c->c_write_cv );
1061 if ( ber_pvt_sb_needs_read( c->c_sb ) )
1062 slapd_set_read( s, 1 );
1063 if ( ber_pvt_sb_needs_write( c->c_sb ) )
1064 slapd_set_write( s, 1 );
1065 connection_return( c );
1066 ldap_pvt_thread_mutex_unlock( &connections_mutex );