From 2aa036fa0403977fa51812e711a1d5040c9fb5c9 Mon Sep 17 00:00:00 2001 From: Mark Ellzey Date: Thu, 17 Nov 2011 11:59:41 -0500 Subject: [PATCH] Avoid spinning on OpenSSL reads Previously, if some sender were generating data to read on an OpenSSL connection as fast as we could process it, we could easily wind up looping on an openssl do_read operation without ever considering other sockets. The difference between this and the original method in consider_reading() is that it only loops for a single completed *frame* instead of looping until fd is drained or an error condition was triggered. {Patch split out by nickm} --- bufferevent_openssl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index 07dcdf8edb..53a4d686a6 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -766,10 +766,13 @@ consider_reading(struct bufferevent_openssl *bev_ssl) if (bev_ssl->write_blocked_on_read) return; - while ((n_to_read = bytes_to_read(bev_ssl)) != 0) { - r = do_read(bev_ssl, n_to_read); - if (r <= 0) + n_to_read = bytes_to_read(bev_ssl); + + while (n_to_read) { + if (do_read(bev_ssl, n_to_read) <= 0) break; + + n_to_read = SSL_pending(bev_ssl->ssl); } if (!bev_ssl->underlying) {