Skip to content

Commit

Permalink
Avoid spinning on OpenSSL reads
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Mark Ellzey authored and nmathewson committed Nov 17, 2011
1 parent 96c562f commit 2aa036f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bufferevent_openssl.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 2aa036f

Please sign in to comment.