[svn r349] Changed g_thread_pool to GIOWatch.
1.1 --- a/gmyth/src/gmyth_monitor_handler.c Fri Feb 09 20:42:28 2007 +0000
1.2 +++ b/gmyth/src/gmyth_monitor_handler.c Fri Feb 09 21:30:05 2007 +0000
1.3 @@ -75,12 +75,12 @@
1.4 //GThread *monitor_th = NULL;
1.5
1.6 //static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
1.7 -//static gboolean gmyth_monitor_handler_listener( GIOChannel *io_channel,
1.8 -// GIOCondition condition, gpointer data );
1.9 +gboolean gmyth_monitor_handler_listener( GIOChannel *io_channel,
1.10 + GIOCondition io_cond, gpointer data );
1.11
1.12 //gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor );
1.13
1.14 -void gmyth_monitor_handler_listener( GMythMonitorHandler *monitor, gpointer user_data );
1.15 +//void gmyth_monitor_handler_listener( GMythMonitorHandler *monitor, gpointer user_data );
1.16
1.17 static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message );
1.18
1.19 @@ -318,12 +318,12 @@
1.20 gmyth_debug ("Monitor event socket --- hostname: %s, port %d\n", monitor->hostname, monitor->port);
1.21
1.22 /* configure the event socket */
1.23 - if ( NULL == monitor->event_sock ) {
1.24 + //if ( NULL == monitor->event_sock ) {
1.25 if (!gmyth_connect_to_backend_monitor (monitor)) {
1.26 g_printerr( "Connection to backend failed (Event Socket).\n" );
1.27 ret = FALSE;
1.28 }
1.29 - } else {
1.30 + else {
1.31 g_warning("Remote monitor event socket already created.\n");
1.32 }
1.33
1.34 @@ -400,15 +400,14 @@
1.35
1.36 //static void
1.37 //gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
1.38 -//static gboolean
1.39 -//gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
1.40 +gboolean
1.41 +gmyth_monitor_handler_listener( GIOChannel *io_channel, GIOCondition io_cond, gpointer data )
1.42 //gboolean* gmyth_monitor_handler_listener( GMythMonitorHandler *monitor )
1.43 -void
1.44 -gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
1.45 +//void gmyth_monitor_handler_listener (GMythMonitorHandler *monitor, gpointer user_data)
1.46 {
1.47 - //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
1.48 + GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
1.49 GIOStatus io_status;
1.50 - GIOCondition io_cond;
1.51 + //GIOCondition io_cond;
1.52 guint recv = 0;
1.53 gboolean *ret = g_new0( gboolean, 1 );
1.54 *ret = TRUE;
1.55 @@ -417,7 +416,7 @@
1.56
1.57 static guint count = 0;
1.58
1.59 - GIOChannel *io_channel = monitor->event_sock->sd_io_ch;
1.60 + //GIOChannel *io_channel = monitor->event_sock->sd_io_ch;
1.61 //GIOCondition condition = g_io_channel_get_buffer_condition( io_channel );
1.62
1.63 GMythStringList *strlist = NULL;
1.64 @@ -505,7 +504,7 @@
1.65 if (strlist!=NULL)
1.66 g_object_unref( strlist );
1.67
1.68 - return;
1.69 + return *ret;
1.70
1.71 }
1.72
1.73 @@ -587,14 +586,17 @@
1.74 /*
1.75 monitor->monitor_th = g_thread_pool_new( (GThreadFunc)gmyth_monitor_handler_listener,
1.76 monitor, TRUE, NULL );
1.77 - */
1.78 + */
1.79 +
1.80 + /*
1.81 +
1.82 monitor->monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener,
1.83 monitor, 3, TRUE, NULL );
1.84 g_thread_pool_push( monitor->monitor_th, monitor, NULL );
1.85 -
1.86 + */
1.87 //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
1.88 - if ( monitor->monitor_th != NULL )
1.89 - //if ( gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch ) )
1.90 + //if ( monitor->monitor_th != NULL )
1.91 + if ( gmyth_monitor_handler_setup( monitor, monitor->event_sock->sd_io_ch ) )
1.92 {
1.93 gmyth_debug ( "\n[%s]\tOK! Starting listener on the MONITOR event socket...[thread location = %p]\n",
1.94 __FUNCTION__, g_thread_self( ) );
2.1 --- a/gmyth/src/gmyth_monitor_handler.h Fri Feb 09 20:42:28 2007 +0000
2.2 +++ b/gmyth/src/gmyth_monitor_handler.h Fri Feb 09 21:30:05 2007 +0000
2.3 @@ -87,8 +87,10 @@
2.4
2.5 GThreadPool *monitor_th;
2.6
2.7 - // gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor );
2.8 - void (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor, gpointer user_data );
2.9 + //gboolean* (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor );
2.10 + //void (*gmyth_monitor_handler_listener)( GMythMonitorHandler *monitor, gpointer user_data );
2.11 + gboolean (*gmyth_monitor_handler_listener) ( GIOChannel *io_channel,
2.12 + GIOCondition io_cond, gpointer data );
2.13
2.14 gchar *hostname;
2.15 gint port;
3.1 --- a/gmyth/src/gmyth_socket.c Fri Feb 09 20:42:28 2007 +0000
3.2 +++ b/gmyth/src/gmyth_socket.c Fri Feb 09 21:30:05 2007 +0000
3.3 @@ -339,9 +339,11 @@
3.4
3.5 /* disconnect socket */
3.6 gmyth_socket_close_connection (gmyth_socket);
3.7 -
3.8 +
3.9 + /*
3.10 g_free (gmyth_socket->hostname);
3.11 gmyth_socket->hostname = NULL;
3.12 + */
3.13
3.14 g_free (local_hostname);
3.15
3.16 @@ -565,12 +567,14 @@
3.17 g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE);
3.18 g_io_channel_set_encoding (gmyth_socket->sd_io_ch, NULL, NULL );
3.19
3.20 - GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
3.21 + #if 0
3.22 + GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
3.23 /* unset the nonblock flag */
3.24 flags &= ~G_IO_FLAG_NONBLOCK;
3.25 /* unset the nonblocking stuff for some time, because GNUTLS doesn't like
3.26 * that */
3.27 g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
3.28 + #endif
3.29
3.30 ret = ( ret_code == 0 ) ? TRUE : FALSE ;
3.31 if ( !ret )
3.32 @@ -933,7 +937,7 @@
3.33 {
3.34 GIOStatus io_status = G_IO_STATUS_NORMAL;
3.35 GError* error = NULL;
3.36 - gchar *buffer;
3.37 + gchar *buffer = NULL;
3.38
3.39 GString *str = NULL;
3.40
3.41 @@ -943,21 +947,26 @@
3.42 if ( !( gmyth_socket != NULL) )
3.43 return NULL;
3.44
3.45 - GIOCondition io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch);
3.46 + GIOCondition io_cond;
3.47
3.48 /* verify if the input (read) buffer is ready to receive data */
3.49
3.50 //g_static_mutex_lock( &mutex );
3.51 //g_static_rw_lock_reader_lock (&rwlock);
3.52
3.53 - //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
3.54 - buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' ');
3.55 + buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
3.56 + //buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' ');
3.57 if ( NULL == gmyth_socket->sd_io_ch )
3.58 {
3.59 gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port );
3.60 }
3.61 -
3.62 - if ( gmyth_socket->sd_io_ch->is_readable /*&& ( ( io_cond & G_IO_IN ) != 0 )*/ )
3.63 +
3.64 + io_cond = g_io_channel_get_buffer_condition (gmyth_socket->sd_io_ch);
3.65 +/*
3.66 + if ( NULL == gmyth_socket->sd_io_ch->read_buf || ( NULL == gmyth_socket->sd_io_ch->read_buf->str ) )
3.67 + gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd );
3.68 + */
3.69 + if ( gmyth_socket->sd_io_ch->is_readable /*&& !( ( io_cond & G_IO_IN ) == 0 )*/ )
3.70 io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error);
3.71 else
3.72 return g_string_new("");
3.73 @@ -976,9 +985,9 @@
3.74 //return NULL;
3.75 } else {
3.76
3.77 - io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error );
3.78 + //io_status = g_io_channel_flush( gmyth_socket->sd_io_ch, &error );
3.79 /* verify if the input (read) buffer is ready to receive data */
3.80 - io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
3.81 + //io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
3.82
3.83 //if ( ( io_cond & G_IO_IN ) != 0 ) {
3.84 //gchar *buffer_aux = NULL;