]> granicus.if.org Git - libevent/commitdiff
fix #73 and fix http_connection_fail_test to catch it
authorGreg Hazel <ghazel@gmail.com>
Thu, 14 Feb 2013 17:54:56 +0000 (09:54 -0800)
committerGreg Hazel <ghazel@gmail.com>
Thu, 14 Feb 2013 17:54:56 +0000 (09:54 -0800)
http.c
test/regress_http.c

diff --git a/http.c b/http.c
index 3994b917dc24353c41f39857722142eab84d7786..9b96ffb3b2313ec6f91b96d5c557bf491f52f770 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2181,6 +2181,8 @@ evhttp_connection_get_peer(struct evhttp_connection *evcon,
 int
 evhttp_connection_connect(struct evhttp_connection *evcon)
 {
+       int old_state = evcon->state;
+
        if (evcon->state == EVCON_CONNECTING)
                return (0);
 
@@ -2209,8 +2211,11 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
        /* make sure that we get a write callback */
        bufferevent_enable(evcon->bufev, EV_WRITE);
 
+       evcon->state = EVCON_CONNECTING;
+
        if (bufferevent_socket_connect_hostname(evcon->bufev, evcon->dns_base,
                AF_UNSPEC, evcon->address, evcon->port) < 0) {
+               evcon->state = old_state;
                event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed",
                    __func__, evcon->address);
                /* some operating systems return ECONNREFUSED immediately
@@ -2221,8 +2226,6 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
                return (0);
        }
 
-       evcon->state = EVCON_CONNECTING;
-
        return (0);
 }
 
index cc3bf27a8353f2a846643c66cb90ecb68d5eb051..9ece455bb6652d15e299ad004a0ed53bd5742072 100644 (file)
@@ -3013,16 +3013,21 @@ http_stream_in_cancel_test(void *arg)
 static void
 http_connection_fail_done(struct evhttp_request *req, void *arg)
 {
+       struct evhttp_connection *evcon = arg;
+       struct event_base *base = evhttp_connection_get_base(evcon);
+
        /* An ENETUNREACH error results in an unrecoverable
         * evhttp_connection error (see evhttp_connection_fail()).  The
         * connection will be reset, and the user will be notified with a NULL
         * req parameter. */
        tt_assert(!req);
 
+       evhttp_connection_free(evcon);
+
        test_ok = 1;
 
  end:
-       event_base_loopexit(arg, NULL);
+       event_base_loopexit(base, NULL);
 }
 
 /* Test unrecoverable evhttp_connection errors by generating an ENETUNREACH
@@ -3053,7 +3058,7 @@ http_connection_fail_test(void *arg)
         * server using our make request method.
         */
 
-       req = evhttp_request_new(http_connection_fail_done, data->base);
+       req = evhttp_request_new(http_connection_fail_done, evcon);
        tt_assert(req);
 
        if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/") == -1) {
@@ -3065,8 +3070,7 @@ http_connection_fail_test(void *arg)
        tt_int_op(test_ok, ==, 1);
 
  end:
-       if (evcon)
-               evhttp_connection_free(evcon);
+        ;
 }
 
 static void