]> granicus.if.org Git - libevent/commitdiff
Add a trival start of a be_async test.
authorNick Mathewson <nickm@torproject.org>
Tue, 5 May 2009 15:36:28 +0000 (15:36 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 5 May 2009 15:36:28 +0000 (15:36 +0000)
svn:r1276

bufferevent_async.c
evsignal-internal.h
test/regress_iocp.c

index 3f641bffe22cda39def12a67247a6132b4ded9c3..fe5cad898912f8dff5ad202e7f9a6b92bec2aaeb 100644 (file)
@@ -230,6 +230,7 @@ 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);
index fcae1a74067d9a14502b2516621e8ac339426cea..e706f920d0b5105986d651446dd0f77940216f4e 100644 (file)
@@ -28,8 +28,9 @@
 #define _EVSIGNAL_H_
 
 #ifndef evutil_socket_t
-#include "evutil.h"
+#include "event2/util.h"
 #endif
+#include <signal.h>
 
 typedef void (*ev_sighandler_t)(int);
 
index eb33da19d93792dbe8c7ac619e1308eb659bd212..35114cd7d800575006edc60b73188a7ef97e2675 100644 (file)
@@ -29,6 +29,7 @@
 #include <event2/event.h>
 #include <event2/thread.h>
 #include <event2/buffer.h>
+#include <event2/bufferevent.h>
 
 #include "regress.h"
 #include "tinytest.h"
 #include "iocp-internal.h"
 #include "evthread-internal.h"
 
+/* FIXME remove these ones */
+#include <sys/queue.h>
+#include "event2/event_struct.h"
+#include "event-internal.h"
+
 #define MAX_CALLS 16
 struct dummy_overlapped {
        struct event_overlapped eo;
@@ -174,19 +180,77 @@ test_iocp_evbuffer(void *ptr)
        tt_assert(!evbuffer_launch_write(wbuf, 512));
 
 #ifdef WIN32
+       /* FIXME this is stupid. */
        Sleep(1000);
 #endif
 
-       /* Actually test some stuff here. */
+       /* FIXME Actually test some stuff here. */
 
 end:
        evbuffer_free(rbuf);
        evbuffer_free(wbuf);
 }
 
+/*FIXME get this from a header once it's in one. */
+struct bufferevent *
+bufferevent_async_new(struct event_base *base,
+    evutil_socket_t fd, enum bufferevent_options options);
+
+static void
+test_iocp_bufferevent_async(void *ptr)
+{
+       struct basic_test_data *data = ptr;
+       struct event_iocp_port *port = NULL;
+       struct bufferevent *bea1=NULL, *bea2=NULL;
+       char buf[128];
+       size_t n;
+
+
+#ifdef WIN32
+       evthread_use_windows_threads();
+#endif
+
+       port = event_iocp_port_launch();
+       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],
+           BEV_OPT_DEFER_CALLBACKS);
+       tt_assert(bea1);
+       tt_assert(bea2);
+
+       /*FIXME set some callbacks */
+
+       bufferevent_enable(bea1, EV_WRITE);
+       bufferevent_enable(bea2, EV_READ);
+
+       bufferevent_write(bea1, "Hello world", strlen("Hello world")+1);
+
+#ifdef WIN32
+/* FIXME: again, stupid. */
+       Sleep(1000);
+#endif
+       n = bufferevent_read(bea2, buf, sizeof(buf)-1);
+       buf[n]='\0';
+       tt_assert(!strcmp(buf, "Hello world"));
+
+end:
+       /* FIXME: free stuff. */;
+}
+
+
 struct testcase_t iocp_testcases[] = {
        { "port", test_iocp_port, TT_FORK, NULL, NULL },
        { "evbuffer", test_iocp_evbuffer, TT_FORK|TT_NEED_SOCKETPAIR,
          &basic_setup, NULL },
+       { "bufferevent_async", test_iocp_bufferevent_async,
+         TT_FORK|TT_NEED_SOCKETPAIR|TT_NEED_BASE, &basic_setup, NULL },
        END_OF_TESTCASES
 };