Hello, The current code for retrying client HTTP connections doubles the delay after every try, until it reaches 3600 seconds.
Trying to open a connection is not a very expensive process, why go up to only one try every hour? If you enable that feature you might want to catch up quickly as the host recovers. What about adding a way to set the highest delay instead of the hardcoded 3600 seconds like the attached trivial patch? Best regards, -Frank. -- Frank Denis - j [at] pureftpd.org - http://00f.net - http://www.cotery.com
Index: http.c =================================================================== --- http.c (revision 926) +++ http.c (working copy) @@ -1067,7 +1067,7 @@ if (evcon->retry_max < 0 || evcon->retry_cnt < evcon->retry_max) { evtimer_assign(&evcon->retry_ev, evcon->base, evhttp_connection_retry, evcon); evhttp_add_event(&evcon->retry_ev, - MIN(3600, 2 << evcon->retry_cnt), + MIN(evcon->retry_max_delay, 2 << evcon->retry_cnt), HTTP_CONNECT_TIMEOUT); evcon->retry_cnt++; return; @@ -1673,6 +1673,7 @@ evcon->timeout = -1; evcon->retry_cnt = evcon->retry_max = 0; + evcon->retry_max_delay = HTTP_RETRY_MAX_DELAY; if ((evcon->address = mm_strdup(address)) == NULL) { event_warn("%s: strdup failed", __func__); @@ -1735,6 +1736,16 @@ } void +evhttp_connection_set_retries_max_delay(struct evhttp_connection *evcon, + int retry_max_delay) +{ + if (retry_max_delay < 0) + retry_max_delay = HTTP_RETRY_MAX_DELAY; + + evcon->retry_max_delay = retry_max_delay; +} + +void evhttp_connection_set_closecb(struct evhttp_connection *evcon, void (*cb)(struct evhttp_connection *, void *), void *cbarg) { Index: http-internal.h =================================================================== --- http-internal.h (revision 926) +++ http-internal.h (working copy) @@ -16,6 +16,8 @@ #define HTTP_WRITE_TIMEOUT 50 #define HTTP_READ_TIMEOUT 50 +#define HTTP_RETRY_MAX_DELAY 3600 + #define HTTP_PREFIX "http://" #define HTTP_DEFAULTPORT 80 @@ -77,6 +79,7 @@ int timeout; /* timeout in seconds for events */ int retry_cnt; /* retry count */ int retry_max; /* maximum number of retries */ + int retry_max_delay; /* maximum delay in seconds betwen retries */ enum evhttp_connection_state state; Index: include/event2/http.h =================================================================== --- include/event2/http.h (revision 926) +++ include/event2/http.h (working copy) @@ -320,6 +320,10 @@ void evhttp_connection_set_retries(struct evhttp_connection *evcon, int retry_max); +/** Sets the max delay (in seconds) between two retries - -1 for default. */ +void evhttp_connection_set_retries_max_delay(struct evhttp_connection *evcon, + int retry_max_delay); + /** Set a callback for connection close. */ void evhttp_connection_set_closecb(struct evhttp_connection *evcon, void (*)(struct evhttp_connection *, void *), void *);
_______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users