From abcaa6d33f1a993b3e07b66889d86b44700b7c14 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 11 Jul 2014 18:45:19 +0530 Subject: server: Add support for aborting running streams This is useful to cancel streams that are taking too long to encode, etc --- README | 5 +++++ src/main.c | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README b/README index 05389df..50c490a 100644 --- a/README +++ b/README @@ -27,6 +27,11 @@ Reading the webm output stream (GET): The server supports multiple PUT requests on different paths, and multiple GET requests from these paths. +A running/encoding stream can be aborted by sending a GET request with the query +"abort" to a path where a stream is running. + + $ curl -v "http://localhost:8000/somepath?abort" + Usage with souphttp: -------------------- Sending a stream from a file (PUT): diff --git a/src/main.c b/src/main.c index e291b2c..10aa6d9 100644 --- a/src/main.c +++ b/src/main.c @@ -584,21 +584,41 @@ PUT: { if (encoding == SOUP_ENCODING_CONTENT_LENGTH) g_timeout_add_seconds (2, (GSourceFunc)increment_read_timer, ctx); goto out; - } + } GET: { - if (!g_hash_table_contains (ctx_table, soup_uri_get_path (uri))) { + const char *query; + TranscodeServerCtx *server_ctx; + + if (!g_hash_table_contains (ctx_table, + soup_uri_get_path (uri))) { g_print ("No stream on URI: %s\n", soup_uri_get_path (uri)); soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); goto out; } + query = soup_uri_get_query (uri); + if (query && g_strcmp0 (query, "abort") == 0) { + /* We just use the "uri" field for this, so this is OK */ + server_ctx = get_server_ctx_from_msg (msg, ctx_table); + /* Abort all processing for this stream */ + if (!server_ctx->stream_finished) { + /* Close the PUT stream if necessary */ + server_ctx->stream_finished = TRUE; + soup_message_set_status (server_ctx->msg, SOUP_STATUS_OK); + } + /* Disconnect all clients, and shut down the stream */ + stp_cleanup_transcode_server_ctx (server_ctx); + soup_message_set_status (msg, SOUP_STATUS_OK); + goto out; + } + /* Our response will be chunked, and not with a fixed Content-Length */ soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_CHUNKED); /* The request body isn't fixed length, so tell libsoup to * not collect chunks for forming a complete request body */ soup_message_body_set_accumulate (msg->response_body, FALSE); - } + } out: soup_uri_free (uri); -- cgit v0.11.2-2-gd1dd