# HG changeset patch # User rosfran # Date 1165363835 0 # Node ID 4bed4ce6b681eadbde678957436572241ca010c0 # Parent 109630cf20ef100eca84dc6428f12721863c5ddb [svn r200] Put a GThreadPool, for a better memory usage. diff -r 109630cf20ef -r 4bed4ce6b681 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Tue Dec 05 21:57:35 2006 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Wed Dec 06 00:10:35 2006 +0000 @@ -382,7 +382,7 @@ g_object_unref( transfer->monitor ); transfer->monitor = NULL; } - + } gint64 diff -r 109630cf20ef -r 4bed4ce6b681 gmyth/src/gmyth_monitor_handler.c --- a/gmyth/src/gmyth_monitor_handler.c Tue Dec 05 21:57:35 2006 +0000 +++ b/gmyth/src/gmyth_monitor_handler.c Wed Dec 06 00:10:35 2006 +0000 @@ -84,8 +84,9 @@ //static gboolean* myth_control_sock_listener( GIOChannel *io_channel ); //static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, // gpointer data ); +//static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret ); -static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret ); +static void gmyth_monitor_handler_listener ( GMythSocket *gmyth_socket, gboolean* ret ); static GMutex* mutex = NULL; @@ -227,24 +228,34 @@ } static void +gmyth_monitor_handler_print( GString *str, gpointer ptr ) +{ + gmyth_debug( "Backend message event: %s.\n", str->str ); +} + +static void //myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ) -myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret ) +//myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret ) +gmyth_monitor_handler_listener ( GMythSocket *gmyth_socket, gboolean* ret ) { GIOStatus io_status; - GError *error = NULL; - GIOCondition io_cond; - GIOCondition condition; - gchar *trash = NULL; - GByteArray *byte_array = NULL; + //GError *error = NULL; + GIOCondition io_cond; + //gchar *trash = NULL; + //GByteArray *byte_array = NULL; guint recv = 0; ret = g_new0( gboolean, 1 ); *ret = TRUE; //gboolean ret = TRUE; gsize len = 0; - static guint count = 0; + static guint count = 0; + GIOChannel *io_channel = gmyth_socket->sd_io_ch; + GIOCondition condition = g_io_channel_get_buffer_condition( io_channel ); + + GMythStringList *strlist = NULL; //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data; @@ -260,7 +271,7 @@ ++count; gmyth_debug ("%d - Listening on Monitor socket...!\n", count); - + /* condition = g_io_channel_get_buffer_condition( io_channel ); //while ( !has_io_access ) // g_cond_wait( io_watcher_cond, mutex ); @@ -300,19 +311,58 @@ gmyth_debug ("\n\n\n[%s]\tEVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv, byte_array != NULL && byte_array->data != NULL ? (gchar*)byte_array->data : "[no event data]" ); - //} - + //} + */ + //io_status = g_io_channel_set_encoding( io_channel, NULL, &error ); + + guint buffer_size = GMYTHTV_BUFFER_SIZE; + do + { + + gint bytes_sent = 0; + + strlist = gmyth_string_list_new(); + + len = gmyth_socket_read_stringlist( gmyth_socket, strlist ); + + if ( strlist != NULL && gmyth_string_list_length( strlist ) > 0 ) + { + bytes_sent = gmyth_string_list_get_int( strlist, 0 ); // -1 on backend error + gmyth_debug ( "[%s] MONITOR: got SENT buffer message = %d\n", __FUNCTION__, bytes_sent ); + + gmyth_debug ( "[%s] MONITOR: received data buffer from IO event channel... %d strings gone!\n", + __FUNCTION__, len ); + + recv += len; + + /* debug purpose: prints out all the string list elements */ + g_list_foreach( strlist->glist, (GFunc)gmyth_monitor_handler_print, NULL ); + + } + + if (strlist!=NULL) + g_object_unref( strlist ); + + io_cond = g_io_channel_get_buffer_condition( io_channel ); + + } while ( ( io_cond & G_IO_IN ) != 0 ); + + gmyth_debug ("\n\n\n[%s]\tMONITOR EVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv, + strlist != NULL && strlist->glist != NULL ? + gmyth_string_list_get_char_array( strlist, 0 ) : "[no event data]" ); +/* if ( byte_array != NULL ) { g_byte_array_free( byte_array, TRUE ); byte_array = NULL; } - + */ g_usleep( 300 ); } - if ( io_status == G_IO_STATUS_ERROR || error != NULL ) { - gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" ); + if ( io_status == G_IO_STATUS_ERROR ) { + //gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" ); + gmyth_debug ("Error reading MONITOR event socket.\n"); *ret = FALSE; goto clean_up; } @@ -324,11 +374,15 @@ clean_up: + if (strlist!=NULL) + g_object_unref( strlist ); + +/* if ( byte_array != NULL ) { g_byte_array_free( byte_array, TRUE ); byte_array = NULL; } - + */ //return ret; } @@ -359,7 +413,7 @@ } static gboolean* -myth_control_sock_setup( GIOChannel *channel ) +gmyth_monitor_handler_setup( GIOChannel *channel ) { gboolean *ret = g_new0( gboolean, 1 ); //guint src_id = 0; @@ -380,7 +434,7 @@ goto cleanup; } - g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL ); + g_source_set_callback ( source, (GSourceFunc)gmyth_monitor_handler_listener, NULL, NULL ); g_source_attach( source, io_watcher_context ); @@ -414,8 +468,10 @@ if (!g_thread_supported () ) g_thread_init (NULL); - monitor_th = g_thread_pool_new( (GFunc)myth_control_sock_listener, - monitor->event_sock->sd_io_ch, 3, FALSE, NULL ); + monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener, + monitor->event_sock, 3, FALSE, NULL ); + + g_thread_pool_push( monitor_th, monitor->event_sock, NULL ); //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE ) if ( monitor_th != NULL ) diff -r 109630cf20ef -r 4bed4ce6b681 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Tue Dec 05 21:57:35 2006 +0000 +++ b/gmyth/src/gmyth_socket.c Wed Dec 06 00:10:35 2006 +0000 @@ -551,12 +551,12 @@ gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd ); - GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch); + //GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch); /* unset the nonblock flag */ - flags &= ~G_IO_FLAG_NONBLOCK; + //flags &= ~G_IO_FLAG_NONBLOCK; /* unset the nonblocking stuff for some time, because GNUTLS doesn't like * that */ - g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL); + //g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL); ret = ( ret_code == 0 ) ? TRUE : FALSE ; @@ -915,7 +915,7 @@ /* verify if the input (read) buffer is ready to receive data */ - g_static_mutex_lock( &mutex ); + //g_static_mutex_lock( &mutex ); //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); @@ -963,7 +963,7 @@ //} } - g_static_mutex_unlock( &mutex ); + //g_static_mutex_unlock( &mutex ); gmyth_debug ("[%s] Response received from backend: {%s}\n", __FUNCTION__, buffer);