]> granicus.if.org Git - libevent/commitdiff
Expose a narrow window to the IOCP code.
authorNick Mathewson <nickm@torproject.org>
Fri, 23 Oct 2009 22:00:29 +0000 (22:00 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 23 Oct 2009 22:00:29 +0000 (22:00 +0000)
svn:r1459

bufferevent_async.c
bufferevent_sock.c
event.c
include/event2/event.h
iocp-internal.h
test/regress_iocp.c

index e8851234c0a8599e8691acfe5231238bd6138ee1..0399fc888ddaf514ab716e79c46dd88e74b04a55 100644 (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;
index 2f591bd2f5f47bd4a4474e979e587c2ca09918b3..5dec03f899e0847015683e30fbbfc14c840c622d 100644 (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;
 
diff --git a/event.c b/event.c
index a612812117ffd0b4a027f6c7a6049ab65837a190..7078a0a5835132aecd47c13d8a8c365044b6f602 100644 (file)
--- a/event.c
+++ b/event.c
@@ -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)
 {
index 1a96260df923163dd670dd56d145ab848a25cbd0..1e7026d2bfb27cce298da72535a28b367fe36ab8 100644 (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
 };
 
 /**
index f03409f159ce3ee3536b84135f87522838d75a5e..d743bd54207a079f1f926ef7a36755517bf41060 100644 (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
index d103c710816048b1a56ae4a06f61aa135e0f0c2f..51953cbe468b62621924901c70e098eaed066136 100644 (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],