From b8f222e055bbba81790ebf13d294cc30a292c49b Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Thu, 19 Nov 2009 21:14:31 +0000 Subject: [PATCH] On FreeBSD and other OSes, connect can return ECONREFUSED immediately; instead of failing the function call, pretend with faileld in the callback. svn:r1553 --- ChangeLog | 2 +- http.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3c6e4c0..be01b27b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -51,7 +51,7 @@ Changes in 2.0.3-alpha: o Add an evdns_getaddrinfo() function to provide a nonblocking getaddrinfo using evdns, so programs can perform useful hostname lookup. o Finally expose the IOCP-based bufferevent backend. It passes its unit tests, but probably still has some bugs remaining. Code by Nick Mathewson and Christopher Davis. o Numerous other bugfixes. - + o On FreeBSD and other OSes, connect can return ECONREFUSED immediately; instead of failing the function call, pretend with faileld in the callback. Changes in 2.0.2-alpha: o Add a new flag to bufferevents to make all callbacks automatically deferred. diff --git a/http.c b/http.c index 73716779..acbd0b57 100644 --- a/http.c +++ b/http.c @@ -1849,8 +1849,12 @@ evhttp_connection_connect(struct evhttp_connection *evcon) if (socket_connect(evcon->fd, evcon->address, evcon->port) == -1) { event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed", __func__, evcon->address); - EVUTIL_CLOSESOCKET(evcon->fd); evcon->fd = -1; - return (-1); + /* some operating systems return ECONNREFUSED immediately + * when connecting to a local address. the cleanup is going + * to reschedule this function call. + */ + evhttp_connection_cb_cleanup(evcon); + return (0); } /* Set up a callback for successful connection setup */ -- 2.50.1