about summary refs log tree commit diff
path: root/btpd/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'btpd/http.c')
-rw-r--r--btpd/http.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/btpd/http.c b/btpd/http.c
index 9f57212..f1e6b7e 100644
--- a/btpd/http.c
+++ b/btpd/http.c
@@ -19,6 +19,7 @@ enum http_state {
 };
 
 struct http {
+    long t_created;
     enum http_state state;
     char *url;
     CURL *curlh;
@@ -62,6 +63,7 @@ http_get(struct http **ret,
     h->state = HS_ADD;
     h->cb = cb;
     h->cb_arg = arg;
+    h->t_created = btpd_seconds;
     if ((h->curlh = curl_easy_init()) == NULL)
         btpd_err("Fatal error in curl.\n");
 
@@ -88,6 +90,26 @@ http_get(struct http **ret,
     return 0;
 }
 
+long
+http_server_busy_time(const char *url, long s)
+{
+    struct http *h;
+    size_t len = strlen(url);
+
+    pthread_mutex_lock(&m_httpq_lock);
+    h = BTPDQ_LAST(&m_httpq, http_tq);
+    while (h != NULL &&
+            !((h->state == HS_ACTIVE || h->state == HS_ADD) &&
+                strncmp(url, h->url, len) == 0))
+        h = BTPDQ_PREV(h, http_tq, entry);
+    pthread_mutex_unlock(&m_httpq_lock);
+
+    if (h == NULL || btpd_seconds - h->t_created >= s)
+        return 0;
+    else
+        return s - (btpd_seconds - h->t_created);
+}
+
 void
 http_cancel(struct http *http)
 {