int
evhttp_connection_connect(struct evhttp_connection *evcon)
{
+ int old_state = evcon->state;
+
if (evcon->state == EVCON_CONNECTING)
return (0);
/* 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
return (0);
}
- evcon->state = EVCON_CONNECTING;
-
return (0);
}
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
* 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) {
tt_int_op(test_ok, ==, 1);
end:
- if (evcon)
- evhttp_connection_free(evcon);
+ ;
}
static void