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;
#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);
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;
#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;
}
}
+#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)
{
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
};
/**
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
#endif
tt_int_op(evbuffer_get_length(rbuf),==,512);
-
-
+
/* FIXME Actually test some stuff here. */
tt_want(!event_iocp_shutdown(port, 2000));
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],