]> git.sur5r.net Git - openldap/blob - servers/slapd/connection.c
Improved "closing" handling. Remove fd from read set when state
[openldap] / servers / slapd / connection.c
1 #include "portable.h"
2
3 #include <stdio.h>
4
5 #include <ac/errno.h>
6 #include <ac/signal.h>
7 #include <ac/socket.h>
8 #include <ac/string.h>
9 #include <ac/time.h>
10
11 #include "slap.h"
12
13 /* protected by connections_mutex */
14 static ldap_pvt_thread_mutex_t connections_mutex;
15 static Connection *connections = NULL;
16 static int conn_index = -1;
17 static long conn_nextid = 0;
18
19 /* structure state (protected by connections_mutex) */
20 #define SLAP_C_UNINITIALIZED    0x0     /* MUST BE ZERO (0) */
21 #define SLAP_C_UNUSED                   0x1
22 #define SLAP_C_USED                             0x2
23
24 /* connection state (protected by c_mutex ) */
25 #define SLAP_C_INVALID                  0x0     /* MUST BE ZERO (0) */
26 #define SLAP_C_INACTIVE                 0x1     /* zero threads */
27 #define SLAP_C_ACTIVE                   0x2 /* one or more threads */
28 #define SLAP_C_BINDING                  0x3     /* binding */
29 #define SLAP_C_CLOSING                  0x4     /* closing */
30
31 static Connection* connection_get( int s );
32
33 static int connection_input( Connection *c );
34
35 static int connection_op_activate( Connection *conn, Operation *op );
36 static int connection_resched( Connection *conn );
37
38 struct co_arg {
39         Connection      *co_conn;
40         Operation       *co_op;
41 };
42
43 /*
44  * Initialize connection management infrastructure.
45  */
46 int connections_init(void)
47 {
48         int i;
49
50         assert( connections == NULL );
51
52         if( connections != NULL) { /* probably should assert this */
53                 Debug( LDAP_DEBUG_ANY, "connections_init: already initialized.\n",
54                         0, 0, 0 );
55                 return -1;
56         }
57
58         /* should check return of every call */
59         ldap_pvt_thread_mutex_init( &connections_mutex );
60
61         connections = (Connection *) calloc( dtblsize, sizeof(Connection) );
62
63         if( connections == NULL ) {
64                 Debug( LDAP_DEBUG_ANY,
65                         "connections_init: allocation (%d*%ld) of connection array failed.\n",
66                         dtblsize, (long) sizeof(Connection), 0 );
67                 return -1;
68         }
69
70         /*
71          * per entry initialization of the Connection array initialization
72          * will be done by connection_init()
73          */ 
74
75         return 0;
76 }
77
78 static Connection* connection_get( int s )
79 {
80         Connection *c = NULL;
81
82         assert( connections != NULL );
83
84         if(s < 0) {
85                 return NULL;
86         }
87
88 #ifndef HAVE_WINSOCK
89         assert( connections[s].c_struct_state == SLAP_C_USED );
90         assert( connections[s].c_conn_state != SLAP_C_INVALID );
91         assert( connections[s].c_sb.sb_sd != -1 );
92
93         c = &connections[s];
94 #else
95         {
96                 int i;
97
98                 for(i=0; i<dtblsize; i++) {
99                         if( connections[i].c_struct_state == SLAP_C_STRUCT_UNINITIALIZED ) {
100                                 assert( connections[i].c_conn_state == SLAP_C_INVALID );
101                                 assert( connections[s].c_sb.sb_sd == 0 );
102                                 break;
103                         }
104
105                         if( connections[i].c_struct_state == SLAP_C_STRUCT_UNUSED ) {
106                                 assert( connections[i].c_conn_state == SLAP_C_INVALID );
107                                 assert( connections[s].c_sb.sb_sd == -1 );
108                                 continue;
109                         }
110
111                         assert( connections[i].c_struct_state == SLAP_C_STRUCT_USED );
112                         assert( connections[i].c_conn_state != SLAP_C_INVALID );
113                         assert( connections[s].c_sb.sb_sd != -1 );
114
115                         if( connections[i].c_sb.sb_sd == s ) {
116                                 c = &connections[s];
117                                 break;
118                         }
119                 }
120         }
121 #endif
122
123         if( c != NULL ) {
124                 /* we do this BEFORE locking to aid in debugging */
125                 Debug( LDAP_DEBUG_TRACE,
126                         "connection_get(%d): got connid=%ld\n",
127                         s, c->c_connid, 0 );
128
129                 ldap_pvt_thread_mutex_lock( &c->c_mutex );
130         }
131         return c;
132 }
133
134 static void connection_return( Connection *c )
135 {
136         ldap_pvt_thread_mutex_unlock( &c->c_mutex );
137 }
138
139 long connection_init(
140         int s,
141         const char* name,
142         const char* addr)
143 {
144         long id;
145         Connection *c;
146         assert( connections != NULL );
147
148         if( s < 0 ) {
149                 return -1;
150         }
151
152         assert( s >= 0 );
153 #ifndef HAVE_WINSOCK
154         assert( s < dtblsize );
155 #endif
156
157         ldap_pvt_thread_mutex_lock( &connections_mutex );
158
159 #ifndef HAVE_WINSOCK
160         c = &connections[s];
161
162 #else
163         {
164                 int i;
165
166                 for( i=0; i < dtblsize; i++ {
167                         if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
168                                 assert( connections[i].c_sb.sb_sd == 0 );
169                                 c = &connections[i];
170                                 break;
171                         }
172
173                         if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
174                                 assert( connections[i].c_sb.sb_sd == -1 );
175                                 c = &connections[i];
176                                 break;
177                         }
178
179                         assert( connections[i].c_struct_state == SLAP_C_USED );
180                         assert( connections[i].c_conn_state != SLAP_C_INVALID );
181                         assert( connections[i].c_sb.sb_sd != -1 );
182                 }
183
184                 if( c == NULL ) {
185                         ldap_pvt_thread_mutex_unlock( &connections_mutex );
186                         return -1;
187                 }
188         }
189 #endif
190
191         assert( c != NULL );
192         assert( c->c_struct_state != SLAP_C_USED );
193         assert( c->c_conn_state == SLAP_C_INVALID );
194
195         if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
196                 c->c_dn = NULL;
197                 c->c_cdn = NULL;
198                 c->c_client_name = NULL;
199                 c->c_client_addr = NULL;
200                 c->c_ops = NULL;
201                 c->c_pending_ops = NULL;
202
203                 lber_pvt_sb_init( &c->c_sb );
204
205                 /* should check status of thread calls */
206                 ldap_pvt_thread_mutex_init( &c->c_mutex );
207                 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
208                 ldap_pvt_thread_cond_init( &c->c_write_cv );
209
210                 c->c_struct_state = SLAP_C_UNUSED;
211         }
212
213         ldap_pvt_thread_mutex_lock( &c->c_mutex );
214
215         assert( c->c_struct_state == SLAP_C_UNUSED );
216         assert( c->c_dn == NULL );
217         assert( c->c_cdn == NULL );
218         assert( c->c_client_name == NULL );
219         assert( c->c_client_addr == NULL );
220         assert( c->c_ops == NULL );
221         assert( c->c_pending_ops == NULL );
222
223         c->c_client_name = ch_strdup( name == NULL ? "" : name );
224         c->c_client_addr = ch_strdup( addr );
225
226         c->c_n_ops_received = 0;
227 #ifdef LDAP_COUNTERS
228         c->c_n_ops_executing = 0;
229         c->c_n_ops_pending = 0;
230         c->c_n_ops_completed = 0;
231 #endif
232
233         c->c_starttime = slap_get_time();
234
235         lber_pvt_sb_set_desc( &c->c_sb, s );
236         lber_pvt_sb_set_io( &c->c_sb, &lber_pvt_sb_io_tcp, NULL );
237
238         if( lber_pvt_sb_set_nonblock( &c->c_sb, 1 ) < 0 ) {
239                 Debug( LDAP_DEBUG_ANY,
240                         "connection_init(%d, %s, %s): set nonblocking failed\n",
241                         s, c->c_client_name, c->c_client_addr);
242         }
243
244         id = c->c_connid = conn_nextid++;
245
246         c->c_conn_state = SLAP_C_INACTIVE;
247         c->c_struct_state = SLAP_C_USED;
248
249         ldap_pvt_thread_mutex_unlock( &c->c_mutex );
250         ldap_pvt_thread_mutex_unlock( &connections_mutex );
251
252         return id;
253 }
254
255 static void
256 connection_destroy( Connection *c )
257 {
258         assert( connections != NULL );
259         assert( c != NULL );
260         assert( c->c_struct_state != SLAP_C_UNUSED );
261         assert( c->c_conn_state != SLAP_C_INVALID );
262         assert( c->c_ops == NULL );
263
264         c->c_struct_state = SLAP_C_UNUSED;
265         c->c_conn_state = SLAP_C_INVALID;
266
267         c->c_version = 0;
268         c->c_protocol = 0;
269
270         c->c_starttime = 0;
271
272         if(c->c_dn != NULL) {
273                 free(c->c_dn);
274                 c->c_dn = NULL;
275         }
276         if(c->c_cdn != NULL) {
277                 free(c->c_cdn);
278                 c->c_cdn = NULL;
279         }
280         if(c->c_client_name != NULL) {
281                 free(c->c_client_name);
282                 c->c_client_name = NULL;
283         }
284         if(c->c_client_addr != NULL) {
285                 free(c->c_client_addr);
286                 c->c_client_addr = NULL;
287         }
288
289         if ( lber_pvt_sb_in_use(&c->c_sb) ) {
290                 int sd = lber_pvt_sb_get_desc(&c->c_sb);
291
292                 slapd_remove( sd );
293                 lber_pvt_sb_close( &c->c_sb );
294
295                 Statslog( LDAP_DEBUG_STATS,
296                     "conn=%d fd=%d closed.\n",
297                         c->c_connid, sd, 0, 0, 0 );
298         }
299
300         lber_pvt_sb_destroy( &c->c_sb );
301 }
302
303 void connection_closing( Connection *c )
304 {
305         assert( connections != NULL );
306         assert( c != NULL );
307         assert( c->c_struct_state == SLAP_C_USED );
308         assert( c->c_conn_state != SLAP_C_INVALID );
309
310         if( c->c_conn_state != SLAP_C_CLOSING ) {
311                 /* don't listen on this port anymore */
312                 slapd_clr_read( c->c_sb.sb_sd, 1 );
313                 c->c_conn_state = SLAP_C_CLOSING;
314         }
315 }
316
317 static void connection_close( Connection *c )
318 {
319         assert( connections != NULL );
320         assert( c != NULL );
321         assert( c->c_struct_state == SLAP_C_USED );
322         assert( c->c_conn_state == SLAP_C_CLOSING );
323
324         if( c->c_ops != NULL ) {
325                 Debug( LDAP_DEBUG_TRACE,
326                         "connection_close: deferring conn=%ld sd=%d.\n",
327                         c->c_connid, c->c_sb.sb_sd, 0 );
328
329                 return;
330         }
331
332         Debug( LDAP_DEBUG_TRACE, "connection_close: conn=%ld sd=%d.\n",
333                 c->c_connid, c->c_sb.sb_sd, 0 );
334
335         connection_destroy( c );
336 }
337
338 long connections_nextid(void)
339 {
340         long id;
341         assert( connections != NULL );
342
343         ldap_pvt_thread_mutex_lock( &connections_mutex );
344
345         id = conn_nextid;
346
347         ldap_pvt_thread_mutex_unlock( &connections_mutex );
348
349         return id;
350 }
351
352 Connection* connection_first(void)
353 {
354         assert( connections != NULL );
355
356         ldap_pvt_thread_mutex_lock( &connections_mutex );
357
358         assert( conn_index == -1 );
359         conn_index = 0;
360
361         return connection_next(NULL);
362 }
363
364 Connection* connection_next(Connection *c)
365 {
366         assert( connections != NULL );
367         assert( conn_index != -1 );
368         assert( conn_index <= dtblsize );
369
370         if( c != NULL ) {
371                 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
372         }
373
374         c = NULL;
375
376         for(; conn_index < dtblsize; conn_index++) {
377                 if( connections[conn_index].c_struct_state == SLAP_C_UNINITIALIZED ) {
378                         assert( connections[conn_index].c_conn_state == SLAP_C_INVALID );
379 #ifndef HAVE_WINSOCK
380                         continue;
381 #else
382                         break;
383 #endif
384                 }
385
386                 if( connections[conn_index].c_struct_state == SLAP_C_USED ) {
387                         assert( connections[conn_index].c_conn_state != SLAP_C_INVALID );
388                         c = &connections[conn_index++];
389                         break;
390                 }
391
392                 assert( connections[conn_index].c_struct_state == SLAP_C_UNUSED );
393                 assert( connections[conn_index].c_conn_state == SLAP_C_INVALID );
394         }
395
396         if( c != NULL ) {
397                 ldap_pvt_thread_mutex_lock( &c->c_mutex );
398         }
399
400         return c;
401 }
402
403 void connection_done(Connection *c)
404 {
405         assert( connections != NULL );
406         assert( conn_index != -1 );
407         assert( conn_index <= dtblsize );
408
409         if( c != NULL ) {
410                 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
411         }
412
413         conn_index = -1;
414         ldap_pvt_thread_mutex_unlock( &connections_mutex );
415 }
416
417 /*
418  * connection_activity - handle the request operation op on connection
419  * conn.  This routine figures out what kind of operation it is and
420  * calls the appropriate stub to handle it.
421  */
422
423 static void *
424 connection_operation( void *arg_v )
425 {
426         struct co_arg   *arg = arg_v;
427         int tag = arg->co_op->o_tag;
428         Connection *conn = arg->co_conn;
429
430 #ifdef LDAP_COUNTERS
431         ldap_pvt_thread_mutex_lock( &ops_mutex );
432         ops_initiated++;
433         ldap_pvt_thread_mutex_unlock( &ops_mutex );
434 #endif
435
436         switch ( tag ) {
437         case LDAP_REQ_BIND:
438                 do_bind( conn, arg->co_op );
439                 break;
440
441 #ifdef LDAP_COMPAT30
442         case LDAP_REQ_UNBIND_30:
443 #endif
444         case LDAP_REQ_UNBIND:
445                 do_unbind( conn, arg->co_op );
446                 break;
447
448         case LDAP_REQ_ADD:
449                 do_add( conn, arg->co_op );
450                 break;
451
452 #ifdef LDAP_COMPAT30
453         case LDAP_REQ_DELETE_30:
454 #endif
455         case LDAP_REQ_DELETE:
456                 do_delete( conn, arg->co_op );
457                 break;
458
459         case LDAP_REQ_MODRDN:
460                 do_modrdn( conn, arg->co_op );
461                 break;
462
463         case LDAP_REQ_MODIFY:
464                 do_modify( conn, arg->co_op );
465                 break;
466
467         case LDAP_REQ_COMPARE:
468                 do_compare( conn, arg->co_op );
469                 break;
470
471         case LDAP_REQ_SEARCH:
472                 do_search( conn, arg->co_op );
473                 break;
474
475 #ifdef LDAP_COMPAT30
476         case LDAP_REQ_ABANDON_30:
477 #endif
478         case LDAP_REQ_ABANDON:
479                 do_abandon( conn, arg->co_op );
480                 break;
481
482         default:
483                 Debug( LDAP_DEBUG_ANY, "unknown request 0x%lx\n",
484                     arg->co_op->o_tag, 0, 0 );
485                 break;
486         }
487
488 #ifdef LDAP_COUNTERS
489         ldap_pvt_thread_mutex_lock( &ops_mutex );
490         ops_completed++;
491         ldap_pvt_thread_mutex_unlock( &ops_mutex );
492 #endif
493
494         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
495
496 #ifdef LDAP_COUNTERS
497         conn->c_ops_completed++;
498 #endif
499
500         slap_op_remove( &conn->c_ops, arg->co_op );
501         slap_op_free( arg->co_op );
502         arg->co_op = NULL;
503         arg->co_conn = NULL;
504         free( (char *) arg );
505         arg = NULL;
506
507         switch( tag ) {
508 #ifdef LDAP_COMPAT30
509         case LDAP_REQ_UNBIND_30:
510 #endif
511         case LDAP_REQ_UNBIND:
512                 connection_closing( conn );
513                 break;
514
515         case LDAP_REQ_BIND:
516                 if( conn->c_conn_state == SLAP_C_BINDING) {
517                         conn->c_conn_state = SLAP_C_ACTIVE;
518                 }
519         }
520
521         if( conn->c_conn_state == SLAP_C_CLOSING ) {
522                 Debug( LDAP_DEBUG_TRACE,
523                         "connection_operation: attempting closing conn=%ld sd=%d.\n",
524                         conn->c_connid, conn->c_sb.sb_sd, 0 );
525
526                 connection_close( conn );
527         }
528
529         ldap_pvt_thread_mutex_lock( &active_threads_mutex );
530         active_threads--;
531         if( active_threads < 1 ) {
532                 ldap_pvt_thread_cond_signal(&active_threads_cond);
533         }
534         ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
535
536         connection_resched( conn );
537
538         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
539
540         return NULL;
541 }
542
543 int connection_read(int s)
544 {
545         int rc = 0;
546         Connection *c;
547         assert( connections != NULL );
548
549         ldap_pvt_thread_mutex_lock( &connections_mutex );
550
551         c = connection_get( s );
552         if( c == NULL ) {
553                 Debug( LDAP_DEBUG_ANY,
554                         "connection_read(%d): no connection!\n",
555                         s, 0, 0 );
556                 return -1;
557         }
558
559         Debug( LDAP_DEBUG_TRACE,
560                 "connection_read(%d): checking for input on id=%ld\n",
561                 s, c->c_connid, 0 );
562
563 #define CONNECTION_INPUT_LOOP 1
564
565 #ifdef DATA_READY_LOOP
566         while(!rc && lber_pvt_sb_data_ready(&c->c_sb))
567 #elif CONNECTION_INPUT_LOOP
568         while(!rc)
569 #endif
570         {
571                 rc = connection_input( c );
572         }
573
574         if( rc < 0 ) {
575                 Debug( LDAP_DEBUG_TRACE,
576                         "connection_read(%d): input error id=%ld, closing.\n",
577                         s, c->c_connid, 0 );
578
579                 connection_closing( c );
580                 connection_close( c );
581         }
582
583         connection_return( c );
584         ldap_pvt_thread_mutex_unlock( &connections_mutex );
585         return 0;
586 }
587
588 static int
589 connection_input(
590     Connection *conn
591 )
592 {
593         Operation *op;
594         unsigned long   tag, len;
595         long            msgid;
596         BerElement      *ber;
597
598         if ( conn->c_currentber == NULL && (conn->c_currentber = ber_alloc())
599             == NULL ) {
600                 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
601                 return -1;
602         }
603
604         errno = 0;
605         if ( (tag = ber_get_next( &conn->c_sb, &len, conn->c_currentber ))
606             != LDAP_TAG_MESSAGE )
607         {
608                 Debug( LDAP_DEBUG_TRACE,
609                         "ber_get_next on fd %d failed errno %d (%s)\n",
610                         lber_pvt_sb_get_desc(&conn->c_sb), errno,
611                         errno > -1 && errno < sys_nerr ?  sys_errlist[errno] : "unknown" );
612                 Debug( LDAP_DEBUG_TRACE,
613                         "\t*** got %ld of %lu so far\n",
614                         (long)(conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf),
615                         conn->c_currentber->ber_len, 0 );
616
617                 if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
618                         /* log, close and send error */
619                         ber_free( conn->c_currentber, 1 );
620                         conn->c_currentber = NULL;
621
622                         return -1;
623                 }
624
625                 return 1;
626         }
627
628         ber = conn->c_currentber;
629         conn->c_currentber = NULL;
630
631         if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
632                 /* log, close and send error */
633                 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
634                     0 );
635                 ber_free( ber, 1 );
636                 return -1;
637         }
638
639         if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
640                 /* log, close and send error */
641                 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
642                     0 );
643                 ber_free( ber, 1 );
644
645                 return -1;
646         }
647
648 #ifdef LDAP_COMPAT30
649         if ( conn->c_version == 30 ) {
650                 (void) ber_skip_tag( ber, &len );
651         }
652 #endif
653
654         op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++ );
655
656         if ( conn->c_conn_state == SLAP_C_BINDING
657                 || conn->c_conn_state == SLAP_C_CLOSING )
658         {
659                 Debug( LDAP_DEBUG_ANY, "deferring operation\n", 0, 0, 0 );
660                 slap_op_add( &conn->c_pending_ops, op );
661
662         } else {
663                 connection_op_activate( conn, op );
664         }
665
666 #ifdef NO_THREADS
667         if ( conn->c_struct_state != SLAP_C_USED ) {
668                 /* connection must have got closed underneath us */
669                 return 1;
670         }
671 #endif
672         assert( conn->c_struct_state == SLAP_C_USED );
673
674         return 0;
675 }
676
677 static int
678 connection_resched( Connection *conn )
679 {
680         Operation *op;
681
682         if( conn->c_conn_state != SLAP_C_ACTIVE ) {
683                 /* other states need different handling */
684                 return;
685         }
686
687         for( op = slap_op_pop( &conn->c_pending_ops );
688                 op != NULL;
689                 op = slap_op_pop( &conn->c_pending_ops ) )
690         {
691                 connection_op_activate( conn, op );
692
693                 if ( conn->c_conn_state == SLAP_C_BINDING ) {
694                         break;
695                 }
696         }
697 }
698
699 static int connection_op_activate( Connection *conn, Operation *op )
700 {
701         struct co_arg *arg;
702         char *tmpdn;
703         int status;
704         unsigned long tag = op->o_tag;
705
706         if ( conn->c_dn != NULL ) {
707                 tmpdn = ch_strdup( conn->c_dn );
708         } else {
709                 tmpdn = NULL;
710         }
711
712         arg = (struct co_arg *) ch_malloc( sizeof(struct co_arg) );
713         arg->co_conn = conn;
714         arg->co_op = op;
715
716         arg->co_op->o_dn = ch_strdup( tmpdn != NULL ? tmpdn : "" );
717         arg->co_op->o_ndn = dn_normalize_case( ch_strdup( arg->co_op->o_dn ) );
718
719         slap_op_add( &conn->c_ops, arg->co_op );
720
721         if(tag == LDAP_REQ_BIND) {
722                 conn->c_conn_state = SLAP_C_BINDING;
723         }
724
725         if ( tmpdn != NULL ) {
726                 free( tmpdn );
727         }
728
729         ldap_pvt_thread_mutex_lock( &active_threads_mutex );
730         active_threads++;
731         ldap_pvt_thread_mutex_unlock( &active_threads_mutex );
732
733         status = ldap_pvt_thread_create( &arg->co_op->o_tid, 1,
734                                          connection_operation, (void *) arg );
735
736         if ( status != 0 ) {
737                 Debug( LDAP_DEBUG_ANY,
738                 "ldap_pvt_thread_create failed (%d)\n", status, 0, 0 );
739
740                 /* should move op to pending list */
741         }
742
743         return status;
744 }
745
746 int connection_write(int s)
747 {
748         Connection *c;
749         assert( connections != NULL );
750
751         ldap_pvt_thread_mutex_lock( &connections_mutex );
752
753         c = connection_get( s );
754         if( c == NULL ) {
755                 Debug( LDAP_DEBUG_ANY,
756                         "connection_write(%d): no connection!\n",
757                         s, 0, 0 );
758                 return -1;
759         }
760
761         Debug( LDAP_DEBUG_TRACE,
762                 "connection_write(%d): waking output for id=%ld\n",
763                 s, c->c_connid, 0 );
764
765         ldap_pvt_thread_cond_signal( &c->c_write_cv );
766
767         connection_return( c );
768         ldap_pvt_thread_mutex_unlock( &connections_mutex );
769         return 0;
770 }