# HG changeset patch # User rosfran # Date 1171056605 0 # Node ID c9134ac4505438924ef44f10a1e25439b4ec3637 # Parent 4ba9626303753c150ccdae3df44c19b82a0da2ca [svn r349] Changed g_thread_pool to GIOWatch. diff -r 4ba962630375 -r c9134ac45054 gmyth/src/gmyth_monitor_handler.c --- a/gmyth/src/gmyth_monitor_handler.c Fri Feb 09 20:42:28 2007 +0000 +++ b/gmyth/src/gmyth_monitor_handler.c Fri Feb 09 21:30:05 2007 +0000 @@ -75,12 +75,12 @@ //GThread *monitor_th = NULL; //static gboolean* myth_control_sock_listener( GIOChannel *io_channel ); -//static gboolean gmyth_monitor_handler_listener( GIOChannel *io_channel, -// GIOCondition condition, gpointer data ); +gboolean gmyth_monitor_handler_listener( GIOChannel *io_channel, + GIOCondition io_cond, gpointer data ); //gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor ); -void gmyth_monitor_handler_listener( GMythMonitorHandler *monitor, gpointer user_data ); +//void gmyth_monitor_handler_listener( GMythMonitorHandler *monitor, gpointer user_data ); static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message ); @@ -318,12 +318,12 @@ gmyth_debug ("Monitor event socket --- hostname: %s, port %d\n", monitor->hostname, monitor->port); /* configure the event socket */ - if ( NULL == monitor->event_sock ) { + //if ( NULL == monitor->event_sock ) { if (!gmyth_connect_to_backend_monitor (monitor)) { g_printerr( "Connection to backend failed (Event Socket).\n" ); ret = FALSE; } - } else { + else { g_warning("Remote monitor event socket already created.\n"); } @@ -400,15 +400,14 @@ //static void //gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data) -//static gboolean -//gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data ) +gboolean +gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition io_cond, gpointer data ) //gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor ) -void -gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data) +//void gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data) { - //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data; + GMythMonitorHandler *monitor = (GMythMonitorHandler*)data; GIOStatus io_status; - GIOCondition io_cond; + //GIOCondition io_cond; guint recv = 0; gboolean *ret = g_new0( gboolean, 1 ); *ret = TRUE; @@ -417,7 +416,7 @@ static guint count = 0; - GIOChannel *io_channel = monitor->event_sock->sd_io_ch; + //GIOChannel *io_channel = monitor->event_sock->sd_io_ch; //GIOCondition condition = g_io_channel_get_buffer_condition( io_channel ); GMythStringList *strlist = NULL; @@ -505,7 +504,7 @@ if (strlist!=NULL) g_object_unref( strlist ); - return; + return *ret; } @@ -587,14 +586,17 @@ /* monitor->monitor_th = g_thread_pool_new( (GThreadFunc)gmyth_monitor_handler_listener, monitor, TRUE, NULL ); - */ + */ + + /* + monitor->monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener, monitor, 3, TRUE, NULL ); g_thread_pool_push( monitor->monitor_th, monitor, NULL ); - + */ //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE ) - if ( monitor->monitor_th != NULL ) - //if ( gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch ) ) + //if ( monitor->monitor_th != NULL ) + if ( gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch ) ) { gmyth_debug ( "\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n", __FUNCTION__, g_thread_self( ) ); diff -r 4ba962630375 -r c9134ac45054 gmyth/src/gmyth_monitor_handler.h --- a/gmyth/src/gmyth_monitor_handler.h Fri Feb 09 20:42:28 2007 +0000 +++ b/gmyth/src/gmyth_monitor_handler.h Fri Feb 09 21:30:05 2007 +0000 @@ -87,8 +87,10 @@ GThreadPool *monitor_th; - // gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor ); - void (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor, gpointer user_data ); + //gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor ); + //void (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor, gpointer user_data ); + gboolean (*gmyth_monitor_handler_listener) ( GIOChannel *io_channel, + GIOCondition io_cond, gpointer data ); gchar *hostname; gint port; diff -r 4ba962630375 -r c9134ac45054 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Fri Feb 09 20:42:28 2007 +0000 +++ b/gmyth/src/gmyth_socket.c Fri Feb 09 21:30:05 2007 +0000 @@ -339,9 +339,11 @@ /* disconnect socket */ gmyth_socket_close_connection (gmyth_socket); - + + /* g_free (gmyth_socket->hostname); gmyth_socket->hostname = NULL; + */ g_free (local_hostname); @@ -565,12 +567,14 @@ g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE); g_io_channel_set_encoding (gmyth_socket->sd_io_ch, NULL, NULL ); - GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch); + #if 0 + GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch); /* unset the nonblock flag */ 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); + #endif ret = ( ret_code == 0 ) ? TRUE : FALSE ; if ( !ret ) @@ -933,7 +937,7 @@ { GIOStatus io_status = G_IO_STATUS_NORMAL; GError* error = NULL; - gchar *buffer; + gchar *buffer = NULL; GString *str = NULL; @@ -943,21 +947,26 @@ if ( !( gmyth_socket != NULL) ) return NULL; - GIOCondition io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); + GIOCondition io_cond; /* verify if the input (read) buffer is ready to receive data */ //g_static_mutex_lock( &mutex ); //g_static_rw_lock_reader_lock (&rwlock); - //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); - buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); + buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE); + //buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' '); if ( NULL == gmyth_socket->sd_io_ch ) { gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port ); } - - if ( gmyth_socket->sd_io_ch->is_readable /*&& ( ( io_cond & G_IO_IN ) != 0 )*/ ) + + io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch); +/* + if ( NULL == gmyth_socket->sd_io_ch->read_buf || ( NULL == gmyth_socket->sd_io_ch->read_buf->str ) ) + gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd ); + */ + if ( gmyth_socket->sd_io_ch->is_readable /*&& !( ( io_cond & G_IO_IN ) == 0 )*/ ) io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error); else return g_string_new(""); @@ -976,9 +985,9 @@ //return NULL; } else { - io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error ); + //io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error ); /* verify if the input (read) buffer is ready to receive data */ - io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); + //io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); //if ( ( io_cond & G_IO_IN ) != 0 ) { //gchar *buffer_aux = NULL;