* unless a timeout was specifically set for a connection,
* the connection inherits the timeout from the pool.
*/
- if (connection->timeout == -1)
- connection->timeout = pool->timeout;
+ if (!evutil_timerisset(&connection->timeout))
+ evhttp_connection_set_timeout(connection, pool->timeout);
/*
* if we have any requests pending, schedule them with the new
{
struct evhttp_connection *evcon;
TAILQ_FOREACH(evcon, &pool->connections, next) {
- evcon->timeout = timeout_in_secs;
+ evhttp_connection_set_timeout(evcon, timeout_in_secs);
}
pool->timeout = timeout_in_secs;
}
evhttp_error_cb,
evcon);
- if (evcon->timeout == -1)
+ if (!evutil_timerisset(&evcon->timeout)) {
bufferevent_settimeout(evcon->bufev,
HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
- else {
- struct timeval tv;
- tv.tv_sec = evcon->timeout;
- tv.tv_usec = 0;
- bufferevent_set_timeouts(evcon->bufev, &tv, &tv);
+ } else {
+ bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
}
/* try to start requests that have queued up on this connection */
evcon->max_headers_size = EV_SIZE_MAX;
evcon->max_body_size = EV_SIZE_MAX;
- evcon->timeout = -1;
+ evutil_timerclear(&evcon->timeout);
evcon->retry_cnt = evcon->retry_max = 0;
if ((evcon->address = mm_strdup(address)) == NULL) {
evhttp_connection_set_timeout(struct evhttp_connection *evcon,
int timeout_in_secs)
{
- evcon->timeout = timeout_in_secs;
+ if (timeout_in_secs == -1)
+ evhttp_connection_set_timeout_tv(evcon, NULL);
+ else {
+ struct timeval tv;
+ tv.tv_sec = timeout_in_secs;
+ tv.tv_usec = 0;
+ evhttp_connection_set_timeout_tv(evcon, &tv);
+ }
+}
- if (evcon->timeout == -1)
- bufferevent_settimeout(evcon->bufev,
- HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
- else
- bufferevent_settimeout(evcon->bufev,
- evcon->timeout, evcon->timeout);
+void
+evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon,
+ const struct timeval* tv)
+{
+ if (tv) {
+ evcon->timeout = *tv;
+ bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
+ } else {
+ evutil_timerclear(&evcon->timeout);
+ bufferevent_settimeout(evcon->bufev, HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
+ }
}
void
NULL /* evhttp_write_cb */,
evhttp_connection_cb,
evcon);
- bufferevent_settimeout(evcon->bufev, 0,
- evcon->timeout != -1 ? evcon->timeout : HTTP_CONNECT_TIMEOUT);
+ if (!evutil_timerisset(&evcon->timeout))
+ bufferevent_settimeout(evcon->bufev, 0, HTTP_CONNECT_TIMEOUT);
+ else
+ bufferevent_set_timeouts(evcon->bufev, NULL, &evcon->timeout);
/* make sure that we get a write callback */
bufferevent_enable(evcon->bufev, EV_WRITE);
return (NULL);
}
- http->timeout = -1;
+ evutil_timerclear(&http->timeout);
evhttp_set_max_headers_size(http, EV_SIZE_MAX);
evhttp_set_max_body_size(http, EV_SIZE_MAX);
evhttp_set_allowed_methods(http,
void
evhttp_set_timeout(struct evhttp* http, int timeout_in_secs)
{
- http->timeout = timeout_in_secs;
+ if (timeout_in_secs == -1) {
+ evhttp_set_timeout_tv(http, NULL);
+ } else {
+ struct timeval tv;
+ tv.tv_sec = timeout_in_secs;
+ tv.tv_usec = 0;
+ evhttp_set_timeout_tv(http, &tv);
+ }
+}
+
+void
+evhttp_set_timeout_tv(struct evhttp* http, const struct timeval* tv)
+{
+ if (tv) {
+ http->timeout = *tv;
+ } else {
+ evutil_timerclear(&http->timeout);
+ }
}
void
}
/* the timeout can be used by the server to close idle connections */
- if (http->timeout != -1)
- evhttp_connection_set_timeout(evcon, http->timeout);
+ if (evutil_timerisset(&http->timeout))
+ evhttp_connection_set_timeout_tv(evcon, &http->timeout);
/*
* if we want to accept more than one request on a connection,
*/
void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs);
+/**
+ * Set the timeout for an HTTP request.
+ *
+ * @param http an evhttp object
+ * @param tv the timeout, or NULL
+ */
+void evhttp_set_timeout_tv(struct evhttp *http, const struct timeval* tv);
+
/* Request/Response functionality */
/**
void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
ev_uint16_t port);
-/** Sets the timeout for events related to this connection */
+/** Sets the timeout in seconds for events related to this connection */
void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
int timeout_in_secs);
+/** Sets the timeout for events related to this connection. Takes a struct
+ * timeval. */
+void evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon,
+ const struct timeval *tv);
+
/** Sets the retry limit for this connection - -1 repeats indefinitely */
void evhttp_connection_set_retries(struct evhttp_connection *evcon,
int retry_max);