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 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 pthread_mutex_unlock( &active_threads_mutex );
114 unsigned long tag, len;
119 if ( conn->c_currentber == NULL && (conn->c_currentber = ber_alloc())
121 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
126 if ( (tag = ber_get_next( &conn->c_sb, &len, conn->c_currentber ))
127 != LDAP_TAG_MESSAGE ) {
128 Debug( LDAP_DEBUG_TRACE,
129 "ber_get_next on fd %d failed errno %d (%s)\n",
130 conn->c_sb.sb_sd, errno, errno > -1 && errno < sys_nerr ?
131 sys_errlist[errno] : "unknown" );
132 Debug( LDAP_DEBUG_TRACE, "*** got %ld of %lu so far\n",
133 (long)(conn->c_currentber->ber_rwptr - conn->c_currentber->ber_buf),
134 conn->c_currentber->ber_len, 0 );
136 if ( errno != EWOULDBLOCK && errno != EAGAIN ) {
137 /* log, close and send error */
138 ber_free( conn->c_currentber, 1 );
139 conn->c_currentber = NULL;
141 close_connection( conn, conn->c_connid, -1 );
146 ber = conn->c_currentber;
147 conn->c_currentber = NULL;
149 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
150 /* log, close and send error */
151 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
155 close_connection( conn, conn->c_connid, -1 );
159 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
160 /* log, close and send error */
161 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
165 close_connection( conn, conn->c_connid, -1 );
170 if ( conn->c_version == 30 ) {
171 (void) ber_skip_tag( ber, &len );
175 arg = (struct co_arg *) ch_malloc( sizeof(struct co_arg) );
178 pthread_mutex_lock( &conn->c_dnmutex );
179 if ( conn->c_dn != NULL ) {
180 tmpdn = ch_strdup( conn->c_dn );
184 pthread_mutex_unlock( &conn->c_dnmutex );
186 pthread_mutex_lock( &conn->c_opsmutex );
187 arg->co_op = op_add( &conn->c_ops, ber, msgid, tag, tmpdn,
188 conn->c_opsinitiated, conn->c_connid );
189 pthread_mutex_unlock( &conn->c_opsmutex );
191 if ( tmpdn != NULL ) {
195 pthread_attr_init( &attr );
196 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
197 #if !defined(HAVE_PTHREADS_D4)
198 /* POSIX_THREADS or compatible
199 * This is a draft 10 or standard pthreads implementation
201 if ( pthread_create( &arg->co_op->o_tid, &attr,
202 connection_operation, (void *) arg ) != 0 ) {
203 Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
205 pthread_mutex_lock( &active_threads_mutex );
207 pthread_mutex_unlock( &active_threads_mutex );
209 #else /* pthread draft4 */
211 * This is a draft 4 or earlier pthreads implementation
213 if ( pthread_create( &arg->co_op->o_tid, attr,
214 connection_operation, (void *) arg ) != 0 ) {
215 Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 );
217 pthread_mutex_lock( &active_threads_mutex );
219 pthread_mutex_unlock( &active_threads_mutex );
221 #endif /* pthread draft4 */
222 pthread_attr_destroy( &attr );