mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 13:24:43 -04:00
Fix ipv6 support for http. When URL contain domain, not IP address.
Before this patch socket created before domain was resolved, and it always create with AF_INET (ipv4), but we must create socket only after domain was resolved to understad which protocol family have domain address. Thank to Patrick Pelletier, who found this bug.
This commit is contained in:
parent
f324b1dffc
commit
71e709c782
13
http.c
13
http.c
@ -1327,6 +1327,9 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
|
|||||||
struct evhttp_connection *evcon = arg;
|
struct evhttp_connection *evcon = arg;
|
||||||
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
||||||
|
|
||||||
|
if (evcon->fd == -1)
|
||||||
|
evcon->fd = bufferevent_getfd(bufev);
|
||||||
|
|
||||||
switch (evcon->state) {
|
switch (evcon->state) {
|
||||||
case EVCON_CONNECTING:
|
case EVCON_CONNECTING:
|
||||||
if (what & BEV_EVENT_TIMEOUT) {
|
if (what & BEV_EVENT_TIMEOUT) {
|
||||||
@ -1393,6 +1396,9 @@ evhttp_connection_cb(struct bufferevent *bufev, short what, void *arg)
|
|||||||
int error;
|
int error;
|
||||||
ev_socklen_t errsz = sizeof(error);
|
ev_socklen_t errsz = sizeof(error);
|
||||||
|
|
||||||
|
if (evcon->fd == -1)
|
||||||
|
evcon->fd = bufferevent_getfd(bufev);
|
||||||
|
|
||||||
if (!(what & BEV_EVENT_CONNECTED)) {
|
if (!(what & BEV_EVENT_CONNECTED)) {
|
||||||
/* some operating systems return ECONNREFUSED immediately
|
/* some operating systems return ECONNREFUSED immediately
|
||||||
* when connecting to a local address. the cleanup is going
|
* when connecting to a local address. the cleanup is going
|
||||||
@ -2332,6 +2338,7 @@ evhttp_connection_connect_(struct evhttp_connection *evcon)
|
|||||||
EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING));
|
EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING));
|
||||||
evcon->flags |= EVHTTP_CON_OUTGOING;
|
evcon->flags |= EVHTTP_CON_OUTGOING;
|
||||||
|
|
||||||
|
if (evcon->bind_address || evcon->bind_port) {
|
||||||
evcon->fd = bind_socket(
|
evcon->fd = bind_socket(
|
||||||
evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
|
evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
|
||||||
if (evcon->fd == -1) {
|
if (evcon->fd == -1) {
|
||||||
@ -2340,8 +2347,12 @@ evhttp_connection_connect_(struct evhttp_connection *evcon)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up a callback for successful connection setup */
|
|
||||||
bufferevent_setfd(evcon->bufev, evcon->fd);
|
bufferevent_setfd(evcon->bufev, evcon->fd);
|
||||||
|
} else {
|
||||||
|
bufferevent_setfd(evcon->bufev, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up a callback for successful connection setup */
|
||||||
bufferevent_setcb(evcon->bufev,
|
bufferevent_setcb(evcon->bufev,
|
||||||
NULL /* evhttp_read_cb */,
|
NULL /* evhttp_read_cb */,
|
||||||
NULL /* evhttp_write_cb */,
|
NULL /* evhttp_write_cb */,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user