summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-01-22 15:24:28 +0100
committerFelix Fietkau <nbd@openwrt.org>2013-01-22 15:25:01 +0100
commitda607e6272d789ed5dae3b0efff90912fda6f81f (patch)
tree93a827c2cc3f841a5ed4ecdea2d35b97aeae671f
parentf4cdb2ab298f03738bab57e4653e2142d0dfc2ae (diff)
downloadustream-ssl-da607e6272d789ed5dae3b0efff90912fda6f81f.tar.gz
fix read polling by putting the buffer prepare in a loop
allow user to process more than a single buffer's worth of data in one call Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r--ustream-ssl.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/ustream-ssl.c b/ustream-ssl.c
index f403cb5..bbc6b11 100644
--- a/ustream-ssl.c
+++ b/ustream-ssl.c
@@ -80,21 +80,22 @@ static void ustream_ssl_check_conn(struct ustream_ssl *us)
ustream_ssl_error(us, ret);
}
-static void ustream_ssl_notify_read(struct ustream *s, int bytes)
+static bool __ustream_ssl_poll(struct ustream *s)
{
struct ustream_ssl *us = container_of(s->next, struct ustream_ssl, stream);
char *buf;
- int wr = 0, len, ret;
+ int len, ret;
+ bool more = false;
ustream_ssl_check_conn(us);
if (!us->connected || us->error)
- return;
-
- buf = ustream_reserve(&us->stream, 1, &len);
- if (!len)
- return;
+ return false;
do {
+ buf = ustream_reserve(&us->stream, 1, &len);
+ if (!len)
+ break;
+
ret = SSL_read(us->ssl, buf, len);
if (ret < 0) {
ret = SSL_get_error(us->ssl, ret);
@@ -111,13 +112,16 @@ static void ustream_ssl_notify_read(struct ustream *s, int bytes)
break;
}
- buf += ret;
- len -= ret;
- wr += ret;
+ ustream_fill_read(&us->stream, ret);
+ more = true;
} while (1);
- if (wr)
- ustream_fill_read(&us->stream, wr);
+ return more;
+}
+
+static void ustream_ssl_notify_read(struct ustream *s, int bytes)
+{
+ __ustream_ssl_poll(s);
}
static void ustream_ssl_notify_write(struct ustream *s, int bytes)
@@ -186,8 +190,10 @@ static void ustream_ssl_free(struct ustream *s)
static bool ustream_ssl_poll(struct ustream *s)
{
struct ustream_ssl *us = container_of(s, struct ustream_ssl, stream);
+ bool fd_poll;
- return ustream_poll(us->conn);
+ fd_poll = ustream_poll(us->conn);
+ return __ustream_ssl_poll(s) || fd_poll;
}
static void ustream_ssl_stream_init(struct ustream_ssl *us)