summaryrefslogtreecommitdiff
path: root/bufferevent_openssl.c
diff options
context:
space:
mode:
authorMark Ellzey <mark.thomas@mandiant.com>2011-11-17 11:45:49 -0500
committerNick Mathewson <nickm@torproject.org>2011-11-17 11:45:49 -0500
commita186e7320054ed8f508a18876adc9f770c9c4e2e (patch)
treebcad33fc69e63240b531cf084c97257cc16a2653 /bufferevent_openssl.c
parent6660c9a347d3557baee7b9b79d84ad4378be5009 (diff)
downloadlibevent-a186e7320054ed8f508a18876adc9f770c9c4e2e.tar.gz
Refactor amount-to-read calculations in buffervent_ssl consider_reading()
Split up consider_reading()'s conditional checks into another function can_read() for simplicity sake. {Split into a separate patch by nickm}
Diffstat (limited to 'bufferevent_openssl.c')
-rw-r--r--bufferevent_openssl.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c
index 86a8619b..7d822d9e 100644
--- a/bufferevent_openssl.c
+++ b/bufferevent_openssl.c
@@ -704,6 +704,38 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost)
#define READ_DEFAULT 4096
+/* Try to figure out how many bytes to read; return 0 if we shouldn't be
+ * reading. */
+static int
+bytes_to_read(struct bufferevent_openssl *bev)
+{
+ struct evbuffer *input = bev->bev.bev.input;
+ struct event_watermark *wm = &bev->bev.bev.wm_read;
+
+ if (bev->write_blocked_on_read) {
+ return 0;
+ }
+
+ if (! (bev->bev.bev.enabled & EV_READ)) {
+ return 0;
+ }
+
+ if (bev->bev.read_suspended) {
+ return 0;
+ }
+
+ if (wm->high) {
+ if (evbuffer_get_length(input) >= wm->high) {
+ return 0;
+ }
+
+ return wm->high - evbuffer_get_length(input);
+ }
+
+ return READ_DEFAULT;
+}
+
+
/* Things look readable. If write is blocked on read, write till it isn't.
* Read from the underlying buffer until we block or we hit our high-water
* mark.
@@ -712,8 +744,7 @@ static void
consider_reading(struct bufferevent_openssl *bev_ssl)
{
int r;
- struct evbuffer *input = bev_ssl->bev.bev.input;
- struct event_watermark *wm = &bev_ssl->bev.bev.wm_read;
+ int n_to_read;
while (bev_ssl->write_blocked_on_read) {
r = do_write(bev_ssl, WRITE_FRAME);
@@ -722,12 +753,8 @@ consider_reading(struct bufferevent_openssl *bev_ssl)
}
if (bev_ssl->write_blocked_on_read)
return;
- while ((bev_ssl->bev.bev.enabled & EV_READ) &&
- (! bev_ssl->bev.read_suspended) &&
- (! wm->high || evbuffer_get_length(input) < wm->high)) {
- int n_to_read =
- wm->high ? wm->high - evbuffer_get_length(input)
- : READ_DEFAULT;
+
+ while ((n_to_read = bytes_to_read(bev_ssl)) != 0) {
r = do_read(bev_ssl, n_to_read);
if (r <= 0)
break;