Parcourir la source

Changed semantics of cancelled http requests. Before they were reported

as cancelled, or possibly ok or failed if the request had come that far.
Now cancelled requests are silently discarded and doesn't execute the
callback. This makes the http api easier to use. Updated the tracker code
for the new http semantics.
master
Richard Nyberg il y a 19 ans
Parent
révision
8aed86f7d2
2 fichiers modifiés avec 12 ajouts et 49 suppressions
  1. +3
    -2
      btpd/http.c
  2. +9
    -47
      btpd/tracker_req.c

+ 3
- 2
btpd/http.c Voir le fichier

@@ -94,7 +94,7 @@ http_cancel(struct http *http)
pthread_mutex_lock(&m_httpq_lock);
if (http->state == HS_ADD)
http->state = HS_NOADD;
else if (http->state == HS_ACTIVE)
else
http->state = HS_CANCEL;
pthread_mutex_unlock(&m_httpq_lock);
}
@@ -115,7 +115,8 @@ http_td_cb(void *arg)
btpd_log(BTPD_L_ERROR, "Http error for url '%s' (%s).\n", h->url,
curl_easy_strerror(h->res.code));
}
h->cb(h, &h->res, h->cb_arg);
if (h->state != HS_CANCEL)
h->cb(h, &h->res, h->cb_arg);
curl_easy_cleanup(h->curlh);
if (h->res.content != NULL)
free(h->res.content);


+ 9
- 47
btpd/tracker_req.c Voir le fichier

@@ -25,16 +25,8 @@ enum timer_type {
TIMER_RETRY
};

enum http_type {
HTTP_NONE,
HTTP_NORMAL,
HTTP_RETRY,
HTTP_NEW
};

struct tracker {
enum timer_type ttype;
enum http_type htype;
enum tr_event event;
int interval;
unsigned nerrors;
@@ -135,26 +127,14 @@ http_cb(struct http *req, struct http_res *res, void *arg)
{
struct torrent *tp = arg;
struct tracker *tr = tp->tr;
switch (tr->htype) {
case HTTP_NORMAL:
if ((http_succeeded(res) &&
parse_reply(tp, res->content, res->length) == 0)) {
tr->htype = HTTP_NONE;
tr->ttype = TIMER_INTERVAL;
event_add(&tr->timer, (& (struct timeval) { tr->interval, 0 }));
break;
}
case HTTP_RETRY:
tr->htype = HTTP_NONE;
assert(tr->ttype == TIMER_TIMEOUT);
if ((http_succeeded(res) &&
parse_reply(tp, res->content, res->length) == 0)) {
tr->ttype = TIMER_INTERVAL;
event_add(&tr->timer, (& (struct timeval) { tr->interval, 0 }));
} else {
tr->ttype = TIMER_RETRY;
event_add(&tr->timer, RETRY_WAIT);
break;
case HTTP_NEW:
tr->htype = HTTP_NONE;
tr_send(tp, tr->event);
break;
default:
abort();
}
}

@@ -165,16 +145,12 @@ timer_cb(int fd, short type, void *arg)
struct tracker *tr = tp->tr;
switch (tr->ttype) {
case TIMER_TIMEOUT:
http_cancel(tr->req);
tr->htype = HTTP_RETRY;
tr->ttype = TIMER_NONE;
case TIMER_RETRY:
tr_send(tp, tp->tr->event);
break;
case TIMER_INTERVAL:
tr_send(tp, TR_EV_EMPTY);
break;
case TIMER_RETRY:
tr_send(tp, tr->event);
break;
default:
abort();
}
@@ -188,22 +164,8 @@ tr_send(struct torrent *tp, enum tr_event event)

struct tracker *tr = tp->tr;
tr->event = event;
switch (tr->htype) {
case HTTP_NORMAL:
tr->htype = HTTP_NEW;
tr->ttype = TIMER_NONE;
event_del(&tr->timer);
if (tr->ttype == TIMER_TIMEOUT)
http_cancel(tr->req);
return;
case HTTP_RETRY:
tr->htype = HTTP_NEW;
return;
case HTTP_NEW:
return;
default:
tr->htype = HTTP_NORMAL;
}

tr->ttype = TIMER_TIMEOUT;
event_add(&tr->timer, REQ_TIMEOUT);



Chargement…
Annuler
Enregistrer