summaryrefslogtreecommitdiff
path: root/src/lib.c
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2014-07-15 17:50:51 (GMT)
committerNirbheek Chauhan <nirbheek@centricular.com>2014-07-15 17:50:51 (GMT)
commit507f8c8a73e2f373c2b50db6490688689fc88517 (patch)
treee69cd5fa0ae4a8f094c62a97e69bd26b5b55229f /src/lib.c
parentd941945543dfd412813ea68dcab70fe57b8b8273 (diff)
downloadsoup-transcoding-proxy-507f8c8a73e2f373c2b50db6490688689fc88517.zip
soup-transcoding-proxy-507f8c8a73e2f373c2b50db6490688689fc88517.tar.gz
server: Make cleanup on server exit and EOS more reliable
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/lib.c b/src/lib.c
index bd5a8d6..062a8be 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -24,6 +24,13 @@
static void stp_disconnect_cleanup_client (TranscodeClientCtx *ctx);
+static gboolean
+invoke_g_hash_table_remove (TranscodeServerCtx *ctx)
+{
+ g_hash_table_remove (ctx->parent_ctx_table, ctx->path);
+ return FALSE;
+}
+
gboolean
stp_on_gst_bus_message (GstBus *bus,
GstMessage *msg,
@@ -44,12 +51,19 @@ stp_on_gst_bus_message (GstBus *bus,
* hasn't already finished, so we check that */
if (!ctx->stream_finished)
soup_message_set_status (ctx->msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
- /* FIXME: hash tables are not threadsafe */
- g_hash_table_remove (ctx->parent_ctx_table, ctx->path);
+ /* Cleanup in the default main context,
+ * because GHashTable is not thread-safe */
+ g_main_context_invoke_full (NULL, G_PRIORITY_HIGH,
+ (GSourceFunc)invoke_g_hash_table_remove,
+ ctx, NULL);
break;
case GST_MESSAGE_EOS:
g_debug ("End of file");
- g_hash_table_remove (ctx->parent_ctx_table, ctx->path);
+ /* Cleanup in the default main context,
+ * because GHashTable is not thread-safe */
+ g_main_context_invoke_full (NULL, G_PRIORITY_HIGH,
+ (GSourceFunc)invoke_g_hash_table_remove,
+ ctx, NULL);
break;
default:
//stp_print_status ("%s\n", gst_message_type_get_name (msg->type));
@@ -146,6 +160,8 @@ stp_disconnect_cleanup_client (TranscodeClientCtx *ctx)
soup_message_body_complete (ctx->msg->response_body);
g_source_remove (ctx->timeout_handler_id);
+ /* Don't call the "finished" handler and do a double-free */
+ g_signal_handler_disconnect (ctx->msg, ctx->finished_handler_id);
g_free (ctx);
}