2 http.c | 25 ++++++++++++++++++-------
3 1 file changed, 18 insertions(+), 7 deletions(-)
7 @@ -1325,6 +1325,9 @@ evhttp_error_cb(struct bufferevent *bufe
8 struct evhttp_connection *evcon = arg;
9 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
11 + if (evcon->fd == -1)
12 + evcon->fd = bufferevent_getfd(bufev);
14 switch (evcon->state) {
15 case EVCON_CONNECTING:
16 if (what & BEV_EVENT_TIMEOUT) {
17 @@ -1390,6 +1393,9 @@ evhttp_connection_cb(struct bufferevent
19 ev_socklen_t errsz = sizeof(error);
21 + if (evcon->fd == -1)
22 + evcon->fd = bufferevent_getfd(bufev);
24 if (!(what & BEV_EVENT_CONNECTED)) {
25 /* some operating systems return ECONNREFUSED immediately
26 * when connecting to a local address. the cleanup is going
27 @@ -2189,16 +2195,21 @@ evhttp_connection_connect(struct evhttp_
28 EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING));
29 evcon->flags |= EVHTTP_CON_OUTGOING;
31 - evcon->fd = bind_socket(
32 - evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
33 - if (evcon->fd == -1) {
34 - event_debug(("%s: failed to bind to \"%s\"",
35 - __func__, evcon->bind_address));
37 + if (evcon->bind_address || evcon->bind_port) {
38 + evcon->fd = bind_socket(
39 + evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
40 + if (evcon->fd == -1) {
41 + event_debug(("%s: failed to bind to \"%s\"",
42 + __func__, evcon->bind_address));
46 + bufferevent_setfd(evcon->bufev, evcon->fd);
48 + bufferevent_setfd(evcon->bufev, -1);
51 /* Set up a callback for successful connection setup */
52 - bufferevent_setfd(evcon->bufev, evcon->fd);
53 bufferevent_setcb(evcon->bufev,
54 NULL /* evhttp_read_cb */,
55 NULL /* evhttp_write_cb */,