]> granicus.if.org Git - libevent/commitdiff
Make iocp/listener/error work; don't accept again if lev is disabled.
authorChristopher Davis <chrisd@torproject.org>
Thu, 7 Oct 2010 20:41:39 +0000 (13:41 -0700)
committerNick Mathewson <nickm@torproject.org>
Thu, 7 Oct 2010 22:11:38 +0000 (18:11 -0400)
listener.c
test/regress_listener.c

index 8eb5b5fc9ec7aeb5b51660da090cb07fae347879..bd9cd3f20314ea791ca919a7c6e30fff077daee4 100644 (file)
@@ -89,6 +89,7 @@ struct evconnlistener_iocp {
        struct event_iocp_port *port;
        short n_accepting;
        short shutting_down;
+       short enabled;
        struct accepting_socket **accepting;
 };
 #endif
@@ -472,6 +473,10 @@ start_accepting(struct accepting_socket *as)
        DWORD pending = 0;
        SOCKET s = socket(as->family, SOCK_STREAM, 0);
        int error = 0;
+
+       if (!as->lev->enabled)
+               return 0;
+
        if (s == INVALID_SOCKET) {
                error = WSAGetLastError();
                goto report_err;
@@ -633,6 +638,7 @@ iocp_listener_enable(struct evconnlistener *lev)
            EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base);
 
        LOCK(lev);
+       lev_iocp->enabled = 1;
        for (i = 0; i < lev_iocp->n_accepting; ++i) {
                struct accepting_socket *as = lev_iocp->accepting[i];
                if (!as)
@@ -654,6 +660,7 @@ iocp_listener_disable_impl(struct evconnlistener *lev, int shutdown)
            EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base);
 
        LOCK(lev);
+       lev_iocp->enabled = 0;
        for (i = 0; i < lev_iocp->n_accepting; ++i) {
                struct accepting_socket *as = lev_iocp->accepting[i];
                if (!as)
@@ -757,6 +764,7 @@ evconnlistener_new_async(struct event_base *base,
        lev->port = event_base_get_iocp(base);
        lev->fd = fd;
        lev->event_base = base;
+       lev->enabled = 1;
 
        if (event_iocp_port_associate(lev->port, fd, 1) < 0)
                goto err_free_lev;
index ce7e064fc3c12e571beccea05f6d9c349f3e201b..06c3cf5fa7ab951c3ba2dd8a52810f3d4b823b92 100644 (file)
@@ -204,8 +204,7 @@ struct testcase_t listener_iocp_testcases[] = {
          &basic_setup, NULL},
 
        { "error", regress_listener_error,
-         TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR|TT_ENABLE_IOCP
-            |TT_SKIP/*Remove once err-handling on IOCP listeners is ok*/,
+         TT_FORK|TT_NEED_BASE|TT_NEED_SOCKETPAIR|TT_ENABLE_IOCP,
          &basic_setup, NULL},
 
        END_OF_TESTCASES,