#include "event2/event.h"
#include "event2/buffer.h"
#include "event2/bufferevent.h"
-#include "event2/bufferevent_compat.h"
#include "event2/http_struct.h"
#include "event2/http_compat.h"
#include "event2/util.h"
evcon);
if (!evutil_timerisset(&evcon->timeout)) {
- bufferevent_settimeout(evcon->bufev,
- HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
+ const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 };
+ const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 };
+ bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv);
} else {
bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
}
}
if (bev == NULL) {
- if ((evcon->bufev = bufferevent_new(-1,
- evhttp_read_cb,
- evhttp_write_cb,
- evhttp_error_cb, evcon)) == NULL) {
- event_warn("%s: bufferevent_new failed", __func__);
+ if (!(bev = bufferevent_socket_new(base, -1, 0))) {
+ event_warn("%s: bufferevent_socket_new failed", __func__);
goto error;
}
}
- else {
- bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon);
- evcon->bufev = bev;
- }
+
+ bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon);
+ evcon->bufev = bev;
evcon->state = EVCON_DISCONNECTED;
TAILQ_INIT(&evcon->requests);
if (base != NULL) {
evcon->base = base;
- bufferevent_base_set(base, evcon->bufev);
+ if (bufferevent_get_base(bev) != base)
+ bufferevent_base_set(base, evcon->bufev);
}
-
event_deferred_cb_init(&evcon->read_more_deferred_cb,
evhttp_deferred_read_cb, evcon);
evcon->timeout = *tv;
bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
} else {
+ const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 };
+ const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 };
evutil_timerclear(&evcon->timeout);
- bufferevent_settimeout(evcon->bufev, HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
+ bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv);
}
}
NULL /* evhttp_write_cb */,
evhttp_connection_cb,
evcon);
- if (!evutil_timerisset(&evcon->timeout))
- bufferevent_settimeout(evcon->bufev, 0, HTTP_CONNECT_TIMEOUT);
- else
+ if (!evutil_timerisset(&evcon->timeout)) {
+ const struct timeval conn_tv = { HTTP_CONNECT_TIMEOUT, 0 };
+ bufferevent_set_timeouts(evcon->bufev, NULL, &conn_tv);
+ } else {
bufferevent_set_timeouts(evcon->bufev, NULL, &evcon->timeout);
+ }
/* make sure that we get a write callback */
bufferevent_enable(evcon->bufev, EV_WRITE);