evutil_closesocket(evcon->fd);
evcon->fd = -1;
}
- bufferevent_setfd(evcon->bufev, -1);
+ err = bufferevent_setfd(evcon->bufev, -1);
+ EVUTIL_ASSERT(!err && "setfd");
/* we need to clean up any buffered data */
tmp = bufferevent_get_output(evcon->bufev);
evhttp_connection_start_detectclose(struct evhttp_connection *evcon)
{
evcon->flags |= EVHTTP_CON_CLOSEDETECT;
-
bufferevent_enable(evcon->bufev, EV_READ);
}
evhttp_connection_stop_detectclose(struct evhttp_connection *evcon)
{
evcon->flags &= ~EVHTTP_CON_CLOSEDETECT;
-
bufferevent_disable(evcon->bufev, EV_READ);
}
return (-1);
}
- bufferevent_setfd(evcon->bufev, evcon->fd);
+ if (bufferevent_setfd(evcon->bufev, evcon->fd))
+ return (-1);
} else {
- bufferevent_setfd(evcon->bufev, -1);
+ if (bufferevent_setfd(evcon->bufev, -1))
+ return (-1);
}
/* Set up a callback for successful connection setup */
bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
}
/* make sure that we get a write callback */
- bufferevent_enable(evcon->bufev, EV_WRITE);
+ if (bufferevent_enable(evcon->bufev, EV_WRITE))
+ return (-1);
evcon->state = EVCON_CONNECTING;
evcon->fd = fd;
- bufferevent_enable(evcon->bufev, EV_READ);
- bufferevent_disable(evcon->bufev, EV_WRITE);
- bufferevent_setfd(evcon->bufev, fd);
+ if (bufferevent_setfd(evcon->bufev, fd))
+ goto err;
+ if (bufferevent_enable(evcon->bufev, EV_READ))
+ goto err;
+ if (bufferevent_disable(evcon->bufev, EV_WRITE))
+ goto err;
bufferevent_socket_set_conn_address_(evcon->bufev, sa, salen);
return (evcon);
+
+err:
+ evhttp_connection_free(evcon);
+ return (NULL);
}
static int