Connection write support

This commit is contained in:
Ondřej Kuzník 2017-03-16 12:19:31 +00:00 committed by Ondřej Kuzník
parent 79f7e79f15
commit b49932d637
3 changed files with 41 additions and 2 deletions

View File

@ -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 *

View File

@ -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

View File

@ -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 *