client_write_cb( evutil_socket_t s, short what, void *arg )
{
Connection *c = arg;
+
+ ldap_pvt_thread_mutex_lock( &c->c_io_mutex );
+ Debug( LDAP_DEBUG_CONNS, "client_write_cb: "
+ "have something to write to client %lu\n",
+ c->c_connid );
+
+ if ( ber_flush( c->c_sb, c->c_pendingber, 1 ) ) {
+ int err = sock_errno();
+ if ( err != EWOULDBLOCK && err != EAGAIN ) {
+ ldap_pvt_thread_mutex_lock( &c->c_mutex );
+ ldap_pvt_thread_mutex_unlock( &c->c_io_mutex );
+ client_destroy( c );
+ return;
+ }
+ event_add( c->c_write_event, NULL );
+ }
+ c->c_pendingber = NULL;
+ ldap_pvt_thread_mutex_unlock( &c->c_io_mutex );
}
Connection *
ldap_pvt_thread_mutex_t c_io_mutex; /* only one pdu written at a time */
- BerElement *c_currentber; /* ber we're attempting to read */
- struct berval c_pendingber; /* ber we're attempting to write */
+ BerElement *c_currentber; /* ber we're attempting to read */
+ BerElement *c_pendingber; /* ber we're attempting to write */
#define CONN_IS_TLS 1
#define CONN_IS_CLIENT 4
upstream_write_cb( evutil_socket_t s, short what, void *arg )
{
Connection *c = arg;
+
+ ldap_pvt_thread_mutex_lock( &c->c_io_mutex );
+ Debug( LDAP_DEBUG_CONNS, "upstream_write_cb: "
+ "have something to write to upstream %lu\n",
+ c->c_connid );
+
+ if ( ber_flush( c->c_sb, c->c_pendingber, 1 ) ) {
+ int err = sock_errno();
+ if ( err != EWOULDBLOCK && err != EAGAIN ) {
+ ldap_pvt_thread_mutex_lock( &c->c_mutex );
+ Debug( LDAP_DEBUG_ANY, "upstream_write_cb: "
+ "error writing to connection %ld\n",
+ c->c_connid );
+ ldap_pvt_thread_mutex_unlock( &c->c_io_mutex );
+ upstream_destroy( c );
+ return;
+ }
+ event_add( c->c_write_event, 0 );
+ }
+ c->c_pendingber = NULL;
+ ldap_pvt_thread_mutex_unlock( &c->c_io_mutex );
}
Connection *