void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
int timeout_in_secs);
+/* Sets the retry limit for this connection - -1 repeats indefnitely */
+void evhttp_connection_set_retries(struct evhttp_connection *evcon,
+ int retry_max);
+
/* The connection gets ownership of the request */
int evhttp_make_request(struct evhttp_connection *evcon,
struct evhttp_request *req,
#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
int timeout; /* timeout in seconds for events */
+ int retry_cnt; /* retry count */
+ int retry_max; /* maximum number of retries */
enum evhttp_connection_state state;
event_del(&evcon->ev);
}
+static void
+evhttp_connection_retry(int fd, short what, void *arg)
+{
+ struct evhttp_connection *evcon = arg;
+
+ evcon->state = EVCON_DISCONNECTED;
+ evhttp_connection_connect(evcon);
+}
+
/*
* Call back for asynchronous connection attempt.
*/
event_debug(("%s: connected to \"%s:%d\" on %d\n",
__func__, evcon->address, evcon->port, evcon->fd));
+ /* Reset the retry count as we were successful in connecting */
+ evcon->retry_cnt = 0;
evcon->state = EVCON_CONNECTED;
/* try to start requests that have queued up on this connection */
return;
cleanup:
+ if (evcon->retry_max < 0 || evcon->retry_cnt < evcon->retry_max) {
+ evtimer_set(&evcon->ev, evhttp_connection_retry, evcon);
+ evhttp_add_event(&evcon->ev, 2 << evcon->retry_cnt,
+ HTTP_CONNECT_TIMEOUT);
+ evcon->retry_cnt++;
+ return;
+ }
evhttp_connection_reset(evcon);
/* for now, we just signal all requests by executing their callbacks */
evcon->port = port;
evcon->timeout = -1;
+ evcon->retry_cnt = evcon->retry_max = 0;
if ((evcon->address = strdup(address)) == NULL) {
event_warn("%s: strdup failed", __func__);
evcon->timeout = timeout_in_secs;
}
+void
+evhttp_connection_set_retries(struct evhttp_connection *evcon,
+ int retry_max)
+{
+ evcon->retry_max = retry_max;
+}
+
int
evhttp_connection_connect(struct evhttp_connection *evcon)
{