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().
This commit is contained in:
parent
9080797025
commit
e55e560d4e
@ -310,30 +310,48 @@ httpd_client_send_page(gpointer data, gpointer user_data)
|
|||||||
httpd_client_send(client, page);
|
httpd_client_send(client, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
/**
|
||||||
httpd_output_encode_and_play(struct httpd_output *httpd,
|
* Broadcasts a page struct to all clients.
|
||||||
const void *chunk, size_t size, GError **error)
|
*/
|
||||||
|
static void
|
||||||
|
httpd_output_broadcast_page(struct httpd_output *httpd, struct page *page)
|
||||||
{
|
{
|
||||||
bool success;
|
assert(page != NULL);
|
||||||
struct page *page;
|
|
||||||
|
|
||||||
success = encoder_write(httpd->encoder, chunk, size, error);
|
g_mutex_lock(httpd->mutex);
|
||||||
if (!success)
|
g_list_foreach(httpd->clients, httpd_client_send_page, page);
|
||||||
return false;
|
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_mutex_lock(httpd->mutex);
|
||||||
g_list_foreach(httpd->clients, httpd_client_check_queue, NULL);
|
g_list_foreach(httpd->clients, httpd_client_check_queue, NULL);
|
||||||
g_mutex_unlock(httpd->mutex);
|
g_mutex_unlock(httpd->mutex);
|
||||||
|
|
||||||
while ((page = httpd_output_read_page(httpd)) != NULL) {
|
while ((page = httpd_output_read_page(httpd)) != NULL) {
|
||||||
g_mutex_lock(httpd->mutex);
|
httpd_output_broadcast_page(httpd, page);
|
||||||
|
|
||||||
g_list_foreach(httpd->clients,
|
|
||||||
httpd_client_send_page, page);
|
|
||||||
|
|
||||||
g_mutex_unlock(httpd->mutex);
|
|
||||||
page_unref(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;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user