summaryrefslogtreecommitdiff
path: root/bufferevent_sock.c
diff options
context:
space:
mode:
authorNiels Provos <provos@freebsd.localdomain>2010-02-27 18:59:06 -0800
committerNiels Provos <provos@freebsd.localdomain>2010-02-27 18:59:06 -0800
commit7bc48bfd3ac61aa4ff118cacb44145c6ecda366e (patch)
tree665afdeab0fa9342a678c7425d724e53dcd088b4 /bufferevent_sock.c
parent98edb891f89911ab5bdfa2a26ba2c549c66a3b1f (diff)
downloadlibevent-7bc48bfd3ac61aa4ff118cacb44145c6ecda366e.tar.gz
deal with connect() failing immediately
Diffstat (limited to 'bufferevent_sock.c')
-rw-r--r--bufferevent_sock.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/bufferevent_sock.c b/bufferevent_sock.c
index 2225a2a4..22e76032 100644
--- a/bufferevent_sock.c
+++ b/bufferevent_sock.c
@@ -213,6 +213,12 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
}
if (bufev_p->connecting) {
int c = evutil_socket_finished_connecting(fd);
+ /* we need to fake the error if the connection was refused
+ * immediately - usually connection to localhost on BSD */
+ if (bufev_p->connection_refused) {
+ bufev_p->connection_refused = 0;
+ c = -1;
+ }
if (c == 0)
goto done;
@@ -395,11 +401,19 @@ bufferevent_socket_connect(struct bufferevent *bev,
result = 0;
goto done;
}
- } else {
+ } if (r == 1) {
/* The connect succeeded already. How very BSD of it. */
result = 0;
bufev_p->connecting = 1;
event_active(&bev->ev_write, EV_WRITE, 1);
+ } else {
+ /* The connect failed already. How very BSD of it. */
+ if (! be_socket_enable(bev, EV_WRITE)) {
+ bufev_p->connection_refused = 1;
+ bufev_p->connecting = 1;
+ result = 0;
+ goto done;
+ }
}
goto done;