From c991317409f7787223fc11541100d0b0f60afa20 Mon Sep 17 00:00:00 2001 From: Mike Smellie Date: Mon, 19 Jul 2010 15:31:19 +1200 Subject: [PATCH] Change bufferevent_openssl::do_write so it doesn't call SSL_write with a 0 length buffer I was running into a problem when using bufferevent_openssl with a very simple echo server. My server simply bufferevent_read_buffer 'd data into an evbuffer and then passed that evbuffer straight to bufferevent_write_buffer. The problem was every now and again the write would fail for no apparent reason. I tracked it down to SSL_write being called with the amount of data to send being 0. This patch alters do_write in bufferevent_openssl so that it skips io_vecs with 0 length. --- bufferevent_openssl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index c1f18454ac..d89390d736 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -617,6 +617,12 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost) if (bev_ssl->bev.write_suspended) break; + /* SSL_write will (reasonably) return 0 if we tell it to + send 0 data. Skip this case so we don't interpret the + result as an error */ + if (space[i].iov_len == 0) + continue; + r = SSL_write(bev_ssl->ssl, space[i].iov_base, space[i].iov_len); if (r > 0) {