summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzat Khuzhin <a3at.mail@gmail.com>2013-01-23 02:45:32 +0400
committerAzat Khuzhin <a3at.mail@gmail.com>2015-10-08 11:44:49 +0300
commit502c043a3aadabba8ce85db2832654676811bf8b (patch)
treedde62ed476e0c97835eaf2ae8d9ade2e32d49dc7
parent571dbac81af7a378d6fad0728c3eb3d7be89785f (diff)
downloadlibevent-502c043a3aadabba8ce85db2832654676811bf8b.tar.gz
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.
-rw-r--r--http.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/http.c b/http.c
index 377597ea..ea70de50 100644
--- a/http.c
+++ b/http.c
@@ -1325,6 +1325,9 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
struct evhttp_connection *evcon = arg;
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
+ if (evcon->fd == -1)
+ evcon->fd = bufferevent_getfd(bufev);
+
switch (evcon->state) {
case EVCON_CONNECTING:
if (what & BEV_EVENT_TIMEOUT) {
@@ -1390,6 +1393,9 @@ evhttp_connection_cb(struct bufferevent *bufev, short what, void *arg)
int error;
ev_socklen_t errsz = sizeof(error);
+ if (evcon->fd == -1)
+ evcon->fd = bufferevent_getfd(bufev);
+
if (!(what & BEV_EVENT_CONNECTED)) {
/* some operating systems return ECONNREFUSED immediately
* when connecting to a local address. the cleanup is going
@@ -2191,16 +2197,21 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING));
evcon->flags |= EVHTTP_CON_OUTGOING;
- evcon->fd = bind_socket(
- evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
- if (evcon->fd == -1) {
- event_debug(("%s: failed to bind to \"%s\"",
- __func__, evcon->bind_address));
- return (-1);
+ if (evcon->bind_address || evcon->bind_port) {
+ evcon->fd = bind_socket(
+ evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
+ if (evcon->fd == -1) {
+ event_debug(("%s: failed to bind to \"%s\"",
+ __func__, evcon->bind_address));
+ return (-1);
+ }
+
+ bufferevent_setfd(evcon->bufev, evcon->fd);
+ } else {
+ bufferevent_setfd(evcon->bufev, -1);
}
/* Set up a callback for successful connection setup */
- bufferevent_setfd(evcon->bufev, evcon->fd);
bufferevent_setcb(evcon->bufev,
NULL /* evhttp_read_cb */,
NULL /* evhttp_write_cb */,