]> granicus.if.org Git - libevent/commitdiff
Avoid spinning on OpenSSL reads
authorMark Ellzey <mark.thomas@mandiant.com>
Thu, 17 Nov 2011 16:59:41 +0000 (11:59 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 17 Nov 2011 16:59:41 +0000 (11:59 -0500)
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

index 07dcdf8edb95a5f7cc2adb0aff5bc18c237848b0..53a4d686a61b93ce6579507a8491a2259720814a 100644 (file)
@@ -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) {