From 495c227f59093543dcc8f72e699e146ec9f82d10 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 18 Aug 2011 11:41:55 -0400 Subject: [PATCH 1/2] IOCP: don't launch reads or writes on an unconnected socket --- bufferevent_async.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bufferevent_async.c b/bufferevent_async.c index 76a16162..87ba404c 100644 --- a/bufferevent_async.c +++ b/bufferevent_async.c @@ -188,7 +188,7 @@ bev_async_consider_writing(struct bufferevent_async *beva) /* Don't write if there's a write in progress, or we do not * want to write, or when there's nothing left to write. */ - if (beva->write_in_progress) + if (beva->write_in_progress || beva->bev.connecting) return; if (!beva->ok || !(bev->enabled&EV_WRITE) || !evbuffer_get_length(bev->output)) { @@ -234,7 +234,7 @@ bev_async_consider_reading(struct bufferevent_async *beva) /* Don't read if there is a read in progress, or we do not * want to read. */ - if (beva->read_in_progress) + if (beva->read_in_progress || beva->bev.connecting) return; if (!beva->ok || !(bev->enabled&EV_READ)) { bev_async_del_read(beva); @@ -324,7 +324,11 @@ be_async_enable(struct bufferevent *buf, short what) if (!bev_async->ok) return -1; - /* NOTE: This interferes with non-blocking connect */ + if (bev_async->bev.connecting) { + /* Don't launch anything during connection attempts. */ + return 0; + } + if (what & EV_READ) BEV_RESET_GENERIC_READ_TIMEOUT(buf); if (what & EV_WRITE) From 6acfbdd83ab0ecd435928db4eafac862209080ea Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 18 Aug 2011 12:35:27 -0400 Subject: [PATCH 2/2] Make overlapped reads result in evbuffer callbacks getting invoked --- buffer.c | 2 +- buffer_iocp.c | 3 +++ evbuffer-internal.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/buffer.c b/buffer.c index 744c8a9e..98f5a0b2 100644 --- a/buffer.c +++ b/buffer.c @@ -444,7 +444,7 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred) } } -static inline void +void evbuffer_invoke_callbacks(struct evbuffer *buffer) { if (TAILQ_EMPTY(&buffer->callbacks)) { diff --git a/buffer_iocp.c b/buffer_iocp.c index f3f96f44..2d3a1b17 100644 --- a/buffer_iocp.c +++ b/buffer_iocp.c @@ -126,6 +126,9 @@ evbuffer_commit_read(struct evbuffer *evbuf, ev_ssize_t nBytes) buf->read_in_progress = 0; evbuf->total_len += nBytes; + evbuf->n_add_for_cb += nBytes; + + evbuffer_invoke_callbacks(evbuf); _evbuffer_decref_and_unlock(evbuf); } diff --git a/evbuffer-internal.h b/evbuffer-internal.h index 7fc8b914..5879f874 100644 --- a/evbuffer-internal.h +++ b/evbuffer-internal.h @@ -270,6 +270,8 @@ int _evbuffer_read_setup_vecs(struct evbuffer *buf, ev_ssize_t howmuch, /** Set the parent bufferevent object for buf to bev */ void evbuffer_set_parent(struct evbuffer *buf, struct bufferevent *bev); +void evbuffer_invoke_callbacks(struct evbuffer *buf); + #ifdef __cplusplus } #endif