19 * connection_activity - handle the request operation op on connection
20 * conn. This routine figures out what kind of operation it is and
21 * calls the appropriate stub to handle it.
25 connection_operation( void *arg_v )
27 struct co_arg *arg = arg_v;
30 pthread_mutex_lock( &arg->co_conn->c_opsmutex );
31 arg->co_conn->c_opsinitiated++;
32 pthread_mutex_unlock( &arg->co_conn->c_opsmutex );
34 pthread_mutex_lock( &ops_mutex );
36 pthread_mutex_unlock( &ops_mutex );
38 switch ( arg->co_op->o_tag ) {
40 do_bind( arg->co_conn, arg->co_op );
44 case LDAP_REQ_UNBIND_30:
47 do_unbind( arg->co_conn, arg->co_op );
51 do_add( arg->co_conn, arg->co_op );
55 case LDAP_REQ_DELETE_30:
58 do_delete( arg->co_conn, arg->co_op );
62 do_modrdn( arg->co_conn, arg->co_op );
66 do_modify( arg->co_conn, arg->co_op );
69 case LDAP_REQ_COMPARE:
70 do_compare( arg->co_conn, arg->co_op );
74 do_search( arg->co_conn, arg->co_op );
78 case LDAP_REQ_ABANDON_30:
80 case LDAP_REQ_ABANDON:
81 do_abandon( arg->co_conn, arg->co_op );
85 Debug( LDAP_DEBUG_ANY, "unknown request 0x%lx\n",
86 arg->co_op->o_tag, 0, 0 );
90 pthread_mutex_lock( &arg->co_conn->c_opsmutex );
91 arg->co_conn->c_opscompleted++;
92 slap_op_delete( &arg->co_conn->c_ops, arg->co_op );
93 pthread_mutex_unlock( &arg->co_conn->c_opsmutex );
97 pthread_mutex_lock( &ops_mutex );
99 pthread_mutex_unlock( &ops_mutex );
101 pthread_mutex_lock( &active_threads_mutex );
103 if( active_threads < 1 ) {
104 pthread_cond_signal(&active_threads_cond);
106 pthread_mutex_unlock( &active_threads_mutex );
115 #ifndef HAVE_PTHREAD_DETACH
120 unsigned long tag, len;
125 if ( conn->c_currentber == NULL && (conn->c_currentber = ber_alloc())
127 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
132 if ( (tag = ber_get_next( &conn->c_sb, &len, conn->c_currentber ))
133 != LDAP_TAG_MESSAGE ) {
134 Debug( LDAP_DEBUG_TRACE,
135 "ber_get_next on fd %d failed errno %d (%s)\n",
136 conn->c_sb.sb_sd, errno, errno > -1 && errno < sys_nerr ?
137 sys_errlist[errno] : "unknown" );
138 Debug( LDAP_DEBUG_TRACE, "*** got %ld of %lu so far\n",
139 (long)(conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf),
140 conn->c_currentber->ber_len, 0 );
142 if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
143 /* log, close and send error */
144 ber_free( conn->c_currentber, 1 );
145 conn->c_currentber = NULL;
147 close_connection( conn, conn->c_connid, -1 );
152 ber = conn->c_currentber;
153 conn->c_currentber = NULL;
155 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
156 /* log, close and send error */
157 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
161 close_connection( conn, conn->c_connid, -1 );
165 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
166 /* log, close and send error */
167 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
171 close_connection( conn, conn->c_connid, -1 );
176 if ( conn->c_version == 30 ) {
177 (void) ber_skip_tag( ber, &len );
181 arg = (struct co_arg *) ch_malloc( sizeof(struct co_arg) );
184 pthread_mutex_lock( &conn->c_dnmutex );
185 if ( conn->c_dn != NULL ) {
186 tmpdn = ch_strdup( conn->c_dn );
190 pthread_mutex_unlock( &conn->c_dnmutex );
192 pthread_mutex_lock( &conn->c_opsmutex );
193 arg->co_op = slap_op_add( &conn->c_ops, ber, msgid, tag, tmpdn,
194 conn->c_opsinitiated, conn->c_connid );
195 pthread_mutex_unlock( &conn->c_opsmutex );
197 if ( tmpdn != NULL ) {
201 #ifdef HAVE_PTHREAD_DETACH
202 if ( status = pthread_create( &arg->co_op->o_tid, NULL,
203 connection_operation, (void *) arg ) != 0 ) {
204 Debug( LDAP_DEBUG_ANY, "pthread_create failed (%d)\n", status, 0, 0 );
206 pthread_mutex_lock( &active_threads_mutex );
208 pthread_mutex_unlock( &active_threads_mutex );
211 #if !defined(HAVE_PTHREADS_D4)
212 pthread_detach( arg->co_op->o_tid );
214 pthread_detach( &arg->co_op->o_tid );
217 #else /* !pthread detach */
219 pthread_attr_init( &attr );
220 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
221 #if !defined(HAVE_PTHREADS_D4)
222 /* POSIX_THREADS or compatible
223 * This is a draft 10 or standard pthreads implementation
225 if ( status = pthread_create( &arg->co_op->o_tid, &attr,
226 connection_operation, (void *) arg ) != 0 ) {
227 Debug( LDAP_DEBUG_ANY, "pthread_create failed (%d)\n", status, 0, 0 );
229 pthread_mutex_lock( &active_threads_mutex );
231 pthread_mutex_unlock( &active_threads_mutex );
233 #else /* pthread draft4 */
235 * This is a draft 4 or earlier pthreads implementation
237 if ( status = pthread_create( &arg->co_op->o_tid, attr,
238 connection_operation, (void *) arg ) != 0 ) {
239 Debug( LDAP_DEBUG_ANY, "pthread_create failed (%d)\n", status, 0, 0 );
241 pthread_mutex_lock( &active_threads_mutex );
243 pthread_mutex_unlock( &active_threads_mutex );
245 #endif /* pthread draft4 */
246 pthread_attr_destroy( &attr );