summaryrefslogtreecommitdiff
path: root/bufferevent_async.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-05-05 14:18:14 +0000
committerNick Mathewson <nickm@torproject.org>2009-05-05 14:18:14 +0000
commitb69d03b5a8eaf906575d44615e5bf0cab6fbe66a (patch)
treedbe06debd48b0a7e5e4b6ad46f67c6f42f9c3e23 /bufferevent_async.c
parent6b21fe2be89c2be0974aa125fc2c3fe12e24522e (diff)
downloadlibevent-b69d03b5a8eaf906575d44615e5bf0cab6fbe66a.tar.gz
Add a constructor for bufferevent_async.
svn:r1274
Diffstat (limited to 'bufferevent_async.c')
-rw-r--r--bufferevent_async.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/bufferevent_async.c b/bufferevent_async.c
index 2889ce95..3f641bff 100644
--- a/bufferevent_async.c
+++ b/bufferevent_async.c
@@ -67,7 +67,7 @@ static void be_async_adj_timeouts(struct bufferevent *);
static int be_async_flush(struct bufferevent *, short, enum bufferevent_flush_mode);
const struct bufferevent_ops bufferevent_ops_async = {
- "socket",
+ "socket_async",
0,
be_async_enable,
be_async_disable,
@@ -229,3 +229,50 @@ be_async_flush(struct bufferevent *bev, short what,
{
return 0;
}
+
+struct bufferevent *
+bufferevent_async_new(struct event_base *base,
+ evutil_socket_t fd, enum bufferevent_options options);
+
+struct bufferevent *
+bufferevent_async_new(struct event_base *base,
+ evutil_socket_t fd, enum bufferevent_options options)
+{
+ struct bufferevent_async *bev_a;
+ struct bufferevent *bev;
+ struct event_iocp_port *iocp;
+
+ options |= BEV_OPT_THREADSAFE;
+
+ if (!(iocp = event_base_get_iocp(base)))
+ return NULL;
+
+ if (event_iocp_port_associate(iocp, fd, 1)<0)
+ return NULL;
+
+ if (!(bev_a = mm_calloc(1, sizeof(struct bufferevent_async))))
+ return NULL;
+
+ bev = &bev_a->bev.bev;
+ if (!(bev->input = evbuffer_overlapped_new(fd))) {
+ mm_free(bev_a);
+ return NULL;
+ }
+ if (!(bev->output = evbuffer_overlapped_new(fd))) {
+ evbuffer_free(bev->input);
+ mm_free(bev_a);
+ return NULL;
+ }
+
+ if (bufferevent_init_common(&bev_a->bev, base, &bufferevent_ops_async,
+ options)<0)
+ goto err;
+
+ evbuffer_add_cb(bev->input, be_async_inbuf_callback, bev);
+ evbuffer_add_cb(bev->output, be_async_outbuf_callback, bev);
+
+ return bev;
+err:
+ bufferevent_free(&bev_a->bev.bev);
+ return NULL;
+}