Use stream_end() to do the cleanup in stream_fail_cb()

Introduce a new 'failed' parameter to stream_end() as some actions shouldn't
be done when cleaning up after a connection failure.
This commit is contained in:
Julien BLACHE 2009-12-08 19:52:51 +01:00
parent 93287e8259
commit ab760903b1
1 changed files with 9 additions and 16 deletions

View File

@ -107,13 +107,14 @@ static pthread_t tid_httpd;
static void static void
stream_end(struct stream_ctx *st) stream_end(struct stream_ctx *st, int failed)
{ {
/* This is an extension to the stock evhttp */ /* This is an extension to the stock evhttp */
st->req->fail_cb = NULL; st->req->fail_cb = NULL;
st->req->fail_cb_arg = NULL; st->req->fail_cb_arg = NULL;
evhttp_send_reply_end(st->req); if (!failed)
evhttp_send_reply_end(st->req);
evbuffer_free(st->evbuf); evbuffer_free(st->evbuf);
@ -137,7 +138,7 @@ stream_chunk_resched_cb(struct evhttp_connection *evcon, void *arg)
{ {
DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming\n"); DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming\n");
stream_end(st); stream_end(st, 0);
} }
} }
@ -159,7 +160,7 @@ stream_chunk_xcode_cb(int fd, short event, void *arg)
else else
DPRINTF(E_LOG, L_HTTPD, "Transcoding error, file id %d\n", st->id); DPRINTF(E_LOG, L_HTTPD, "Transcoding error, file id %d\n", st->id);
stream_end(st); stream_end(st, 0);
return; return;
} }
@ -210,7 +211,7 @@ stream_chunk_xcode_cb(int fd, short event, void *arg)
{ {
DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming (xcode)\n"); DPRINTF(E_LOG, L_HTTPD, "Could not re-add one-shot event for streaming (xcode)\n");
stream_end(st); stream_end(st, 0);
return; return;
} }
} }
@ -231,7 +232,7 @@ stream_chunk_raw_cb(int fd, short event, void *arg)
else else
DPRINTF(E_LOG, L_HTTPD, "Streaming error, file id %d\n", st->id); DPRINTF(E_LOG, L_HTTPD, "Streaming error, file id %d\n", st->id);
stream_end(st); stream_end(st, 0);
return; return;
} }
@ -257,18 +258,10 @@ stream_fail_cb(struct evhttp_request *req, void *arg)
DPRINTF(E_LOG, L_HTTPD, "Connection failed; stopping streaming of file ID %d\n", st->id); DPRINTF(E_LOG, L_HTTPD, "Connection failed; stopping streaming of file ID %d\n", st->id);
req->fail_cb = NULL;
req->fail_cb_arg = NULL;
/* Stop streaming */ /* Stop streaming */
event_del(&st->ev); event_del(&st->ev);
/* Cleanup */ stream_end(st, 1);
evbuffer_free(st->evbuf);
if (st->xcode)
transcode_cleanup(st->xcode);
free(st);
} }