[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] bev_ssl: Be more specific in event callbacks
evhttp is very strict when checking the event flags while reading the
response body:
evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
{
<snip>
case EVCON_READING_BODY:
if (!req->chunked && req->ntoread < 0
&& what == (BEV_EVENT_READING|BEV_EVENT_EOF)) {
/* EOF on read can be benign */
evhttp_connection_done(evcon);
return;
}
break;
bev_ssl currently only reports EVENT_EOF when the connection is
closed, so it confuses evhttp. This patch makes bev_ssl additionally
set one of BEV_EVENT_{READING|WRITING}, as appropriate, when the
connection is closed.
From f7d21c69ac8b0c57fab6ba4c7afe2250c646c35e Mon Sep 17 00:00:00 2001
From: Catalin Patulea <catalinp@xxxxxxxxxx>
Date: Mon, 21 Nov 2011 19:24:50 -0500
Subject: [PATCH 1/2] bev_ssl: Be more specific in event callbacks. evhttp in particular gets confused without at least one of BEV_EVENT_{READING|WRITING}.
---
bufferevent_openssl.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c
index 89497fd..3ca906b 100644
--- a/bufferevent_openssl.c
+++ b/bufferevent_openssl.c
@@ -483,7 +483,7 @@ clear_wbor(struct bufferevent_openssl *bev_ssl)
}
static void
-conn_closed(struct bufferevent_openssl *bev_ssl, int errcode, int ret)
+conn_closed(struct bufferevent_openssl *bev_ssl, int when, int errcode, int ret)
{
int event = BEV_EVENT_ERROR;
int dirty_shutdown = 0;
@@ -529,6 +529,8 @@ conn_closed(struct bufferevent_openssl *bev_ssl, int errcode, int ret)
stop_reading(bev_ssl);
stop_writing(bev_ssl);
+ /* when is BEV_EVENT_{READING|WRITING} */
+ event = when | event;
_bufferevent_run_eventcb(&bev_ssl->bev.bev, event);
}
@@ -604,7 +606,7 @@ do_read(struct bufferevent_openssl *bev_ssl, int n_to_read)
return -1;
break;
default:
- conn_closed(bev_ssl, err, r);
+ conn_closed(bev_ssl, BEV_EVENT_READING, err, r);
break;
}
blocked = 1;
@@ -682,7 +684,7 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost)
bev_ssl->last_write = space[i].iov_len;
break;
default:
- conn_closed(bev_ssl, err, r);
+ conn_closed(bev_ssl, BEV_EVENT_WRITING, err, r);
bev_ssl->last_write = -1;
break;
}
@@ -979,7 +981,7 @@ do_handshake(struct bufferevent_openssl *bev_ssl)
}
return 0;
default:
- conn_closed(bev_ssl, err, r);
+ conn_closed(bev_ssl, BEV_EVENT_READING, err, r);
return -1;
}
}
--
1.7.3.1