]> granicus.if.org Git - libevent/commitdiff
When working without a current event base, don't try to use IOCP listeners
authorNick Mathewson <nickm@torproject.org>
Thu, 18 Feb 2010 05:27:35 +0000 (00:27 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 18 Feb 2010 05:27:35 +0000 (00:27 -0500)
This fixes a bug turned up with the http unit tests, where we create
the evhttp object using an implicit (NULL) event_base.  This failed
pretty badly when we tried to use IOCP-based listeners.  We could
hunt for the current base from inside listener.c in the future, or
get the iocp base some other way, but for now this is probably the safest
solution.

listener.c

index 0777250278ea7fef310a9bfab983146da980ccb7..9a8e99dda3be2544b8c95033af3286955cec7a46 100644 (file)
@@ -117,7 +117,7 @@ evconnlistener_new(struct event_base *base,
        struct evconnlistener_event *lev;
 
 #ifdef WIN32
-       if (event_base_get_iocp(base)) {
+       if (base && event_base_get_iocp(base)) {
                const struct win32_extension_fns *ext =
                        event_get_win32_extension_fns();
                if (ext->AcceptEx && ext->GetAcceptExSockaddrs)
@@ -345,7 +345,7 @@ new_accepting_socket(struct evconnlistener_iocp *lev, int family)
        event_deferred_cb_init(&res->deferred,
                accepted_socket_invoke_user_cb, res);
 
-       InitializeCriticalSection(&res->lock);
+       InitializeCriticalSectionAndSpinCount(&res->lock, 1000);
 
        return res;
 }
@@ -558,7 +558,7 @@ evconnlistener_new_async(struct event_base *base,
        struct evconnlistener_iocp *lev;
        int i;
 
-       if (!event_base_get_iocp(base))
+       if (!base || !event_base_get_iocp(base))
                goto err;
 
        /* XXXX duplicate code */
@@ -590,7 +590,7 @@ evconnlistener_new_async(struct event_base *base,
        if (event_iocp_port_associate(lev->port, fd, 1) < 0)
                goto err_free_lev;
 
-       InitializeCriticalSection(&lev->lock);
+       InitializeCriticalSectionAndSpinCount(&lev->lock, 1000);
 
        lev->n_accepting = N_SOCKETS_PER_LISTENER;
        lev->accepting = mm_calloc(lev->n_accepting,