http_async_client: add parameters to enable/set tcp keepalive
[sip-router] / src / modules / http_async_client / http_multi.c
index 1dd4b13..43936a7 100644 (file)
@@ -526,8 +526,24 @@ int new_request(str *query, http_m_params_t *query_params, http_multi_cbe_t cb,
        if (cell->params.password) {
                curl_easy_setopt(cell->easy, CURLOPT_PASSWORD, cell->params.password);
        }
+    
+    /* enable tcp keepalives for the handler */
+       if (cell->params.tcp_keepalive) {
+               LM_DBG("Enabling TCP keepalives\n");
+               curl_easy_setopt(cell->easy, CURLOPT_TCP_KEEPALIVE, 1L);
+               
+               if (cell->params.tcp_ka_idle) {
+                       curl_easy_setopt(cell->easy, CURLOPT_TCP_KEEPIDLE, cell->params.tcp_ka_idle);
+                       LM_DBG("CURLOPT_TCP_KEEPIDLE set to %d\n", cell->params.tcp_ka_idle);
+               }
 
-       LM_DBG("Adding easy %p to multi %p (%.*s)\n", cell->easy, g->multi, query->len, query->s);
+               if (cell->params.tcp_ka_interval) {
+                       curl_easy_setopt(cell->easy, CURLOPT_TCP_KEEPINTVL, cell->params.tcp_ka_interval);
+                       LM_DBG("CURLOPT_TCP_KEEPINTERVAL set to %d\n", cell->params.tcp_ka_interval);
+               }
+       }
+       
+    LM_DBG("Adding easy %p to multi %p (%.*s)\n", cell->easy, g->multi, query->len, query->s);
        rc = curl_multi_add_handle(g->multi, cell->easy);
        if (check_mcode(rc, cell->error) < 0) {
                LM_ERR("error adding curl handler: %s\n", cell->error);