From b49932d637bed49172ef76f3f6cfd3e8bbf23acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Thu, 16 Mar 2017 12:19:31 +0000 Subject: [PATCH] Connection write support --- servers/lloadd/client.c | 18 ++++++++++++++++++ servers/lloadd/slap.h | 4 ++-- servers/lloadd/upstream.c | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/servers/lloadd/client.c b/servers/lloadd/client.c index 7dfac6a486..faee2637f5 100644 --- a/servers/lloadd/client.c +++ b/servers/lloadd/client.c @@ -42,6 +42,24 @@ void 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 * diff --git a/servers/lloadd/slap.h b/servers/lloadd/slap.h index bceed14bac..7eebeeaca0 100644 --- a/servers/lloadd/slap.h +++ b/servers/lloadd/slap.h @@ -285,8 +285,8 @@ struct 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 diff --git a/servers/lloadd/upstream.c b/servers/lloadd/upstream.c index 5cc883fdd3..453b9ab0db 100644 --- a/servers/lloadd/upstream.c +++ b/servers/lloadd/upstream.c @@ -39,6 +39,27 @@ void 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 *