mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 13:58:58 -04:00
Merge remote-tracking branch 'origin/patches-2.0'
This commit is contained in:
commit
9709461457
7
http.c
7
http.c
@ -2330,6 +2330,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);
|
||||
|
||||
@ -2367,8 +2369,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
|
||||
@ -2379,8 +2384,6 @@ evhttp_connection_connect_(struct evhttp_connection *evcon)
|
||||
return (0);
|
||||
}
|
||||
|
||||
evcon->state = EVCON_CONNECTING;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -3034,16 +3034,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
|
||||
@ -3074,7 +3079,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) {
|
||||
@ -3086,8 +3091,7 @@ http_connection_fail_test(void *arg)
|
||||
tt_int_op(test_ok, ==, 1);
|
||||
|
||||
end:
|
||||
if (evcon)
|
||||
evhttp_connection_free(evcon);
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user