mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Expose a narrow window to the IOCP code.
svn:r1459
This commit is contained in:
parent
c119e4a13f
commit
879420a711
@ -245,14 +245,9 @@ be_async_flush(struct bufferevent *bev, short what,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*FIXME export this */
|
|
||||||
struct bufferevent *
|
struct bufferevent *
|
||||||
bufferevent_async_new(struct event_base *base,
|
bufferevent_async_new(struct event_base *base,
|
||||||
evutil_socket_t fd, enum bufferevent_options options);
|
evutil_socket_t fd, int 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_async *bev_a;
|
||||||
struct bufferevent *bev;
|
struct bufferevent *bev;
|
||||||
|
@ -66,6 +66,9 @@
|
|||||||
#include "mm-internal.h"
|
#include "mm-internal.h"
|
||||||
#include "bufferevent-internal.h"
|
#include "bufferevent-internal.h"
|
||||||
#include "util-internal.h"
|
#include "util-internal.h"
|
||||||
|
#ifdef WIN32
|
||||||
|
#include "iocp-internal.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int be_socket_enable(struct bufferevent *, short);
|
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_private *bufev_p;
|
||||||
struct bufferevent *bufev;
|
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)
|
if ((bufev_p = mm_calloc(1, sizeof(struct bufferevent_private)))== NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
23
event.c
23
event.c
@ -71,6 +71,7 @@
|
|||||||
#include "event2/util.h"
|
#include "event2/util.h"
|
||||||
#include "log-internal.h"
|
#include "log-internal.h"
|
||||||
#include "evmap-internal.h"
|
#include "evmap-internal.h"
|
||||||
|
#include "iocp-internal.h"
|
||||||
|
|
||||||
#ifdef _EVENT_HAVE_EVENT_PORTS
|
#ifdef _EVENT_HAVE_EVENT_PORTS
|
||||||
extern const struct eventop evportops;
|
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);
|
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
|
void
|
||||||
event_base_free(struct event_base *base)
|
event_base_free(struct event_base *base)
|
||||||
{
|
{
|
||||||
|
@ -165,7 +165,9 @@ enum event_base_config_flag {
|
|||||||
EVENT_BASE_FLAG_NOLOCK = 0x01,
|
EVENT_BASE_FLAG_NOLOCK = 0x01,
|
||||||
/** Do not check the EVENT_NO* environment variables when picking
|
/** Do not check the EVENT_NO* environment variables when picking
|
||||||
an event_base. */
|
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
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,8 +149,17 @@ int event_iocp_activate_overlapped(struct event_iocp_port *port,
|
|||||||
uintptr_t key, ev_uint32_t n_bytes);
|
uintptr_t key, ev_uint32_t n_bytes);
|
||||||
|
|
||||||
struct event_base;
|
struct event_base;
|
||||||
|
/* FIXME document. */
|
||||||
struct event_iocp_port *event_base_get_iocp(struct event_base *base);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -187,7 +187,6 @@ test_iocp_evbuffer(void *ptr)
|
|||||||
|
|
||||||
tt_int_op(evbuffer_get_length(rbuf),==,512);
|
tt_int_op(evbuffer_get_length(rbuf),==,512);
|
||||||
|
|
||||||
|
|
||||||
/* FIXME Actually test some stuff here. */
|
/* FIXME Actually test some stuff here. */
|
||||||
|
|
||||||
tt_want(!event_iocp_shutdown(port, 2000));
|
tt_want(!event_iocp_shutdown(port, 2000));
|
||||||
@ -216,15 +215,10 @@ test_iocp_bufferevent_async(void *ptr)
|
|||||||
evthread_use_windows_threads();
|
evthread_use_windows_threads();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
port = event_iocp_port_launch();
|
event_base_start_iocp(data->base);
|
||||||
|
port = event_base_get_iocp(data->base);
|
||||||
tt_assert(port);
|
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],
|
bea1 = bufferevent_async_new(data->base, data->pair[0],
|
||||||
BEV_OPT_DEFER_CALLBACKS);
|
BEV_OPT_DEFER_CALLBACKS);
|
||||||
bea2 = bufferevent_async_new(data->base, data->pair[1],
|
bea2 = bufferevent_async_new(data->base, data->pair[1],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user