Expose a narrow window to the IOCP code.

svn:r1459
This commit is contained in:
Nick Mathewson 2009-10-23 22:00:29 +00:00
parent c119e4a13f
commit 879420a711
6 changed files with 47 additions and 16 deletions

View File

@ -245,14 +245,9 @@ be_async_flush(struct bufferevent *bev, short what,
return 0;
}
/*FIXME export this */
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)
evutil_socket_t fd, int options)
{
struct bufferevent_async *bev_a;
struct bufferevent *bev;

View File

@ -66,6 +66,9 @@
#include "mm-internal.h"
#include "bufferevent-internal.h"
#include "util-internal.h"
#ifdef WIN32
#include "iocp-internal.h"
#endif
/* prototypes */
static int be_socket_enable(struct bufferevent *, short);
@ -266,6 +269,11 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd,
struct bufferevent_private *bufev_p;
struct bufferevent *bufev;
#ifdef WIN32
if (base && base->iocp)
return bufferevent_async_new(base, fd, options);
#endif
if ((bufev_p = mm_calloc(1, sizeof(struct bufferevent_private)))== NULL)
return NULL;

23
event.c
View File

@ -71,6 +71,7 @@
#include "event2/util.h"
#include "log-internal.h"
#include "evmap-internal.h"
#include "iocp-internal.h"
#ifdef _EVENT_HAVE_EVENT_PORTS
extern const struct eventop evportops;
@ -340,9 +341,31 @@ event_base_new_with_config(struct event_config *cfg)
}
}
#ifdef WIN32
if ((cfg->flags & EVENT_BASE_FLAG_STARTUP_IOCP) != 0)
event_base_start_iocp(base);
#endif
return (base);
}
int
event_base_start_iocp(struct event_base *base)
{
#ifdef WIN32
if (base->iocp)
return 0;
base->iocp = event_iocp_port_launch();
if (!base->iocp) {
event_warnx("%s: Couldn't launch IOCP", __func__);
return -1;
}
return 0;
#else
return -1;
#endif
}
void
event_base_free(struct event_base *base)
{

View File

@ -165,7 +165,9 @@ enum event_base_config_flag {
EVENT_BASE_FLAG_NOLOCK = 0x01,
/** Do not check the EVENT_NO* environment variables when picking
an event_base. */
EVENT_BASE_FLAG_IGNORE_ENV = 0x02
EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
/** Windows only: enable the IOCP dispatcher at startup */
EVENT_BASE_FLAG_STARTUP_IOCP = 0x04
};
/**

View File

@ -149,8 +149,17 @@ int event_iocp_activate_overlapped(struct event_iocp_port *port,
uintptr_t key, ev_uint32_t n_bytes);
struct event_base;
/* FIXME document. */
struct event_iocp_port *event_base_get_iocp(struct event_base *base);
/* FIXME document. */
int event_base_start_iocp(struct event_base *base);
/* FIXME document. */
struct bufferevent *bufferevent_async_new(struct event_base *base,
evutil_socket_t fd, int options);
#ifdef __cplusplus
}
#endif

View File

@ -186,8 +186,7 @@ test_iocp_evbuffer(void *ptr)
#endif
tt_int_op(evbuffer_get_length(rbuf),==,512);
/* FIXME Actually test some stuff here. */
tt_want(!event_iocp_shutdown(port, 2000));
@ -216,15 +215,10 @@ test_iocp_bufferevent_async(void *ptr)
evthread_use_windows_threads();
#endif
port = event_iocp_port_launch();
event_base_start_iocp(data->base);
port = event_base_get_iocp(data->base);
tt_assert(port);
#ifdef WIN32
/* FIXME set this indirectly once there is an interface to do that. */
data->base->iocp = port;
#endif
bea1 = bufferevent_async_new(data->base, data->pair[0],
BEV_OPT_DEFER_CALLBACKS);
bea2 = bufferevent_async_new(data->base, data->pair[1],