From e55e560d4e48eaa9d2791b56a52a52bc6620df82 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 5 May 2009 22:43:28 +0200 Subject: [PATCH] httpd_output: moved code to httpd_output_encoder_to_clients() Moved some code from httpd_output_encode_and_play() into separate functions httpd_output_broadcast_page() and httpd_output_encoder_to_clients(). --- src/output/httpd_output_plugin.c | 46 ++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/output/httpd_output_plugin.c b/src/output/httpd_output_plugin.c index 883dff773..e045e8b5a 100644 --- a/src/output/httpd_output_plugin.c +++ b/src/output/httpd_output_plugin.c @@ -310,30 +310,48 @@ httpd_client_send_page(gpointer data, gpointer user_data) httpd_client_send(client, page); } -static bool -httpd_output_encode_and_play(struct httpd_output *httpd, - const void *chunk, size_t size, GError **error) +/** + * Broadcasts a page struct to all clients. + */ +static void +httpd_output_broadcast_page(struct httpd_output *httpd, struct page *page) { - bool success; - struct page *page; + assert(page != NULL); - success = encoder_write(httpd->encoder, chunk, size, error); - if (!success) - return false; + g_mutex_lock(httpd->mutex); + g_list_foreach(httpd->clients, httpd_client_send_page, page); + g_mutex_unlock(httpd->mutex); +} + +/** + * Broadcasts data from the encoder to all clients. + */ +static void +httpd_output_encoder_to_clients(struct httpd_output *httpd) +{ + struct page *page; g_mutex_lock(httpd->mutex); g_list_foreach(httpd->clients, httpd_client_check_queue, NULL); g_mutex_unlock(httpd->mutex); while ((page = httpd_output_read_page(httpd)) != NULL) { - g_mutex_lock(httpd->mutex); - - g_list_foreach(httpd->clients, - httpd_client_send_page, page); - - g_mutex_unlock(httpd->mutex); + httpd_output_broadcast_page(httpd, page); page_unref(page); } +} + +static bool +httpd_output_encode_and_play(struct httpd_output *httpd, + const void *chunk, size_t size, GError **error) +{ + bool success; + + success = encoder_write(httpd->encoder, chunk, size, error); + if (!success) + return false; + + httpd_output_encoder_to_clients(httpd); return true; }