13 extern Operation *op_add();
14 extern int active_threads;
15 extern pthread_mutex_t active_threads_mutex;
16 extern pthread_mutex_t new_conn_mutex;
17 extern long ops_initiated;
18 extern long ops_completed;
19 extern pthread_mutex_t ops_mutex;
20 extern pthread_t listener_tid;
28 * connection_activity - handle the request operation op on connection
29 * conn. This routine figures out what kind of operation it is and
30 * calls the appropriate stub to handle it.
34 connection_operation( struct co_arg *arg )
38 pthread_mutex_lock( &arg->co_conn->c_opsmutex );
39 arg->co_conn->c_opsinitiated++;
40 pthread_mutex_unlock( &arg->co_conn->c_opsmutex );
42 pthread_mutex_lock( &ops_mutex );
44 pthread_mutex_unlock( &ops_mutex );
46 switch ( arg->co_op->o_tag ) {
48 do_bind( arg->co_conn, arg->co_op );
52 case LDAP_REQ_UNBIND_30:
55 do_unbind( arg->co_conn, arg->co_op );
59 do_add( arg->co_conn, arg->co_op );
63 case LDAP_REQ_DELETE_30:
66 do_delete( arg->co_conn, arg->co_op );
70 do_modrdn( arg->co_conn, arg->co_op );
74 do_modify( arg->co_conn, arg->co_op );
77 case LDAP_REQ_COMPARE:
78 do_compare( arg->co_conn, arg->co_op );
82 do_search( arg->co_conn, arg->co_op );
86 case LDAP_REQ_ABANDON_30:
88 case LDAP_REQ_ABANDON:
89 do_abandon( arg->co_conn, arg->co_op );
93 Debug( LDAP_DEBUG_ANY, "unknown request 0x%x\n",
94 arg->co_op->o_tag, 0, 0 );
98 pthread_mutex_lock( &arg->co_conn->c_opsmutex );
99 arg->co_conn->c_opscompleted++;
100 op_delete( &arg->co_conn->c_ops, arg->co_op );
101 pthread_mutex_unlock( &arg->co_conn->c_opsmutex );
103 free( (char *) arg );
105 pthread_mutex_lock( &ops_mutex );
107 pthread_mutex_unlock( &ops_mutex );
109 pthread_mutex_lock( &active_threads_mutex );
111 pthread_mutex_unlock( &active_threads_mutex );
121 unsigned long tag, len;
126 if ( conn->c_currentber == NULL && (conn->c_currentber = ber_alloc())
128 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
133 if ( (tag = ber_get_next( &conn->c_sb, &len, conn->c_currentber ))
134 != LDAP_TAG_MESSAGE ) {
135 Debug( LDAP_DEBUG_TRACE,
136 "ber_get_next on fd %d failed errno %d (%s)\n",
137 conn->c_sb.sb_sd, errno, errno > -1 && errno < sys_nerr ?
138 sys_errlist[errno] : "unknown" );
139 Debug( LDAP_DEBUG_TRACE, "*** got %d of %d so far\n",
140 conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf,
141 conn->c_currentber->ber_len, 0 );
143 if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
144 /* log, close and send error */
145 ber_free( conn->c_currentber, 1 );
146 conn->c_currentber = NULL;
148 close_connection( conn, conn->c_connid, -1 );
153 ber = conn->c_currentber;
154 conn->c_currentber = NULL;
156 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
157 /* log, close and send error */
158 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%x\n", tag, 0,
162 close_connection( conn, conn->c_connid, -1 );
166 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
167 /* log, close and send error */
168 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%x\n", tag, 0,
172 close_connection( conn, conn->c_connid, -1 );
177 if ( conn->c_version == 30 ) {
178 (void) ber_skip_tag( ber, &len );
182 arg = (struct co_arg *) ch_malloc( sizeof(struct co_arg) );
185 pthread_mutex_lock( &conn->c_dnmutex );
186 if ( conn->c_dn != NULL ) {
187 tmpdn = strdup( conn->c_dn );
191 pthread_mutex_unlock( &conn->c_dnmutex );
193 pthread_mutex_lock( &conn->c_opsmutex );
194 arg->co_op = op_add( &conn->c_ops, ber, msgid, tag, tmpdn,
195 conn->c_opsinitiated, conn->c_connid );
196 pthread_mutex_unlock( &conn->c_opsmutex );
198 if ( tmpdn != NULL ) {
202 pthread_attr_init( &attr );
203 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
204 #if !defined(HAVE_PTHREADS_D4) && !defined(HAVE_DCE)
205 /* POSIX_THREADS or compatible
206 * This is a draft 10 or standard pthreads implementation
208 if ( pthread_create( &arg->co_op->o_tid, &attr,
209 (void *) connection_operation, (void *) arg ) != 0 ) {
210 Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
212 pthread_mutex_lock( &active_threads_mutex );
214 pthread_mutex_unlock( &active_threads_mutex );
216 #else /* pthread draft4 */
218 * This is a draft 4 or earlier pthreads implementation
220 if ( pthread_create( &arg->co_op->o_tid, attr,
221 (void *) connection_operation, (void *) arg ) != 0 ) {
222 Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
224 pthread_mutex_lock( &active_threads_mutex );
226 pthread_mutex_unlock( &active_threads_mutex );
228 #endif /* pthread draft4 */
229 pthread_attr_destroy( &attr );