[svn r200] Put a GThreadPool, for a better memory usage. trunk
authorrosfran
Wed Dec 06 00:10:35 2006 +0000 (2006-12-06)
branchtrunk
changeset 1994bed4ce6b681
parent 198 109630cf20ef
child 200 cc92e11a0c71
[svn r200] Put a GThreadPool, for a better memory usage.
gmyth/src/gmyth_file_transfer.c
gmyth/src/gmyth_monitor_handler.c
gmyth/src/gmyth_socket.c
     1.1 --- a/gmyth/src/gmyth_file_transfer.c	Tue Dec 05 21:57:35 2006 +0000
     1.2 +++ b/gmyth/src/gmyth_file_transfer.c	Wed Dec 06 00:10:35 2006 +0000
     1.3 @@ -382,7 +382,7 @@
     1.4      g_object_unref( transfer->monitor );
     1.5      transfer->monitor = NULL;
     1.6    }
     1.7 -  
     1.8 +
     1.9  }
    1.10  
    1.11  gint64
     2.1 --- a/gmyth/src/gmyth_monitor_handler.c	Tue Dec 05 21:57:35 2006 +0000
     2.2 +++ b/gmyth/src/gmyth_monitor_handler.c	Wed Dec 06 00:10:35 2006 +0000
     2.3 @@ -84,8 +84,9 @@
     2.4  //static gboolean* myth_control_sock_listener( GIOChannel *io_channel );
     2.5  //static gboolean myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, 
     2.6  //				gpointer data );
     2.7 +//static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret );
     2.8  
     2.9 -static void myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret );
    2.10 +static void gmyth_monitor_handler_listener ( GMythSocket *gmyth_socket, gboolean* ret );
    2.11  
    2.12  static GMutex*				mutex 					 = NULL;
    2.13  
    2.14 @@ -227,24 +228,34 @@
    2.15  }
    2.16  
    2.17  static void
    2.18 +gmyth_monitor_handler_print( GString *str, gpointer ptr )
    2.19 +{
    2.20 +	gmyth_debug( "Backend message event: %s.\n", str->str );
    2.21 +}
    2.22 +
    2.23 +static void
    2.24  //myth_control_sock_listener( GIOChannel *io_channel, GIOCondition condition, gpointer data )
    2.25 -myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret )
    2.26 +//myth_control_sock_listener( GIOChannel *io_channel, gboolean* ret )
    2.27 +gmyth_monitor_handler_listener ( GMythSocket *gmyth_socket, gboolean* ret )
    2.28  {
    2.29  
    2.30    GIOStatus io_status;
    2.31 -  GError *error = NULL;
    2.32 -  GIOCondition io_cond;
    2.33 -  GIOCondition condition;
    2.34 -  gchar *trash = NULL;
    2.35 -  GByteArray *byte_array = NULL;
    2.36 +  //GError *error = NULL;
    2.37 +  GIOCondition io_cond;  
    2.38 +  //gchar *trash = NULL;
    2.39 +  //GByteArray *byte_array = NULL;
    2.40    guint recv = 0;
    2.41    ret = g_new0( gboolean, 1 );
    2.42    *ret = TRUE;
    2.43    //gboolean ret = TRUE;
    2.44    gsize len = 0;
    2.45    
    2.46 -  static guint count = 0;  
    2.47 +  static guint count = 0;
    2.48    
    2.49 +  GIOChannel *io_channel = gmyth_socket->sd_io_ch;
    2.50 +  GIOCondition condition = g_io_channel_get_buffer_condition( io_channel );
    2.51 +  
    2.52 +  GMythStringList *strlist = NULL;
    2.53    
    2.54    //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
    2.55    
    2.56 @@ -260,7 +271,7 @@
    2.57    	++count;
    2.58    	
    2.59    	gmyth_debug ("%d - Listening on Monitor socket...!\n", count);
    2.60 -	  	
    2.61 +	  /*	
    2.62  	  condition = g_io_channel_get_buffer_condition( io_channel );	  
    2.63  	  //while ( !has_io_access ) 
    2.64  	  //	g_cond_wait( io_watcher_cond, mutex );
    2.65 @@ -300,19 +311,58 @@
    2.66  	    
    2.67  	    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]" );
    2.68  	    
    2.69 -	  //}	  
    2.70 -	  
    2.71 +	  //}
    2.72 +	   */	   
    2.73 +  	//io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
    2.74 +  	  	
    2.75 +  	guint buffer_size = GMYTHTV_BUFFER_SIZE;
    2.76 +    do 
    2.77 +    {
    2.78 +    	
    2.79 +    	gint bytes_sent = 0;
    2.80 +    	
    2.81 +    	strlist = gmyth_string_list_new();
    2.82 +
    2.83 +      len = gmyth_socket_read_stringlist( gmyth_socket, strlist );
    2.84 +      
    2.85 +	    if ( strlist != NULL && gmyth_string_list_length( strlist ) > 0 ) 
    2.86 +	    { 
    2.87 +		    bytes_sent = gmyth_string_list_get_int( strlist,  0 ); // -1 on backend error
    2.88 +		    gmyth_debug ( "[%s] MONITOR: got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
    2.89 +
    2.90 +	      gmyth_debug ( "[%s] MONITOR: received data buffer from IO event channel... %d strings gone!\n", 
    2.91 +	      		__FUNCTION__, len );
    2.92 +	      		
    2.93 +	      recv += len;
    2.94 +	      
    2.95 +	      /* debug purpose: prints out all the string list elements */
    2.96 +	      g_list_foreach( strlist->glist, (GFunc)gmyth_monitor_handler_print, NULL );
    2.97 +	      
    2.98 +	    }
    2.99 +	    
   2.100 +	    if (strlist!=NULL)
   2.101 +	    	g_object_unref( strlist );
   2.102 +      	
   2.103 +      io_cond = g_io_channel_get_buffer_condition( io_channel );
   2.104 +
   2.105 +    } while ( ( io_cond & G_IO_IN ) != 0 );
   2.106 +    
   2.107 +    gmyth_debug ("\n\n\n[%s]\tMONITOR EVENT: Read %d bytes: %s\n\n\n", __FUNCTION__, recv, 
   2.108 +    					strlist != NULL && strlist->glist != NULL ? 
   2.109 +    					gmyth_string_list_get_char_array( strlist, 0 ) : "[no event data]" );
   2.110 +/*
   2.111  	  if ( byte_array != NULL ) {
   2.112  	  	g_byte_array_free( byte_array, TRUE );
   2.113  	  	byte_array = NULL;
   2.114  	  }
   2.115 -	  
   2.116 +	*/  
   2.117  	  g_usleep( 300 );
   2.118  	  
   2.119    }
   2.120    
   2.121 -  if ( io_status == G_IO_STATUS_ERROR || error != NULL ) {
   2.122 -    gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
   2.123 +  if ( io_status == G_IO_STATUS_ERROR ) {
   2.124 +    //gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
   2.125 +    gmyth_debug ("Error reading MONITOR event socket.\n");
   2.126     	*ret = FALSE;
   2.127     	goto clean_up;   	
   2.128    }
   2.129 @@ -324,11 +374,15 @@
   2.130  
   2.131  clean_up:
   2.132  
   2.133 +  if (strlist!=NULL)
   2.134 +  	g_object_unref( strlist );
   2.135 +
   2.136 +/*
   2.137    if ( byte_array != NULL ) {
   2.138    	g_byte_array_free( byte_array, TRUE );
   2.139    	byte_array = NULL;
   2.140    }
   2.141 -  
   2.142 +  */
   2.143    //return ret;
   2.144  
   2.145  }
   2.146 @@ -359,7 +413,7 @@
   2.147  }    
   2.148  
   2.149  static gboolean*
   2.150 -myth_control_sock_setup( GIOChannel *channel )
   2.151 +gmyth_monitor_handler_setup( GIOChannel *channel )
   2.152  {
   2.153  	gboolean *ret = g_new0( gboolean, 1 );
   2.154  	//guint src_id = 0;
   2.155 @@ -380,7 +434,7 @@
   2.156    	goto cleanup;
   2.157    }
   2.158  
   2.159 -  g_source_set_callback ( source, (GSourceFunc)myth_control_sock_listener, NULL, NULL );
   2.160 +  g_source_set_callback ( source, (GSourceFunc)gmyth_monitor_handler_listener, NULL, NULL );
   2.161  
   2.162    g_source_attach( source, io_watcher_context );
   2.163    
   2.164 @@ -414,8 +468,10 @@
   2.165  	
   2.166  	if (!g_thread_supported () ) 	g_thread_init (NULL);
   2.167  	
   2.168 -  monitor_th = g_thread_pool_new( (GFunc)myth_control_sock_listener, 
   2.169 -  					monitor->event_sock->sd_io_ch, 3, FALSE, NULL );
   2.170 +  monitor_th = g_thread_pool_new( (GFunc)gmyth_monitor_handler_listener, 
   2.171 +  					monitor->event_sock, 3, FALSE, NULL );
   2.172 +  					
   2.173 +  g_thread_pool_push( monitor_th, monitor->event_sock, NULL ); 
   2.174    					
   2.175    //if ( ( ret = g_thread_join( monitor_th ) ) == FALSE )
   2.176    if ( monitor_th != NULL )
     3.1 --- a/gmyth/src/gmyth_socket.c	Tue Dec 05 21:57:35 2006 +0000
     3.2 +++ b/gmyth/src/gmyth_socket.c	Wed Dec 06 00:10:35 2006 +0000
     3.3 @@ -551,12 +551,12 @@
     3.4  
     3.5      gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd );
     3.6      
     3.7 -    GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
     3.8 +    //GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
     3.9  		/* unset the nonblock flag */
    3.10 -		flags &= ~G_IO_FLAG_NONBLOCK;
    3.11 +		//flags &= ~G_IO_FLAG_NONBLOCK;
    3.12  		/* unset the nonblocking stuff for some time, because GNUTLS doesn't like
    3.13  		 * that */
    3.14 -		g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
    3.15 +		//g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
    3.16  
    3.17      ret = ( ret_code == 0 ) ? TRUE : FALSE ;
    3.18  
    3.19 @@ -915,7 +915,7 @@
    3.20  
    3.21      /* verify if the input (read) buffer is ready to receive data */
    3.22  
    3.23 -    g_static_mutex_lock( &mutex );
    3.24 +    //g_static_mutex_lock( &mutex );
    3.25  
    3.26      //buffer = g_new0 (gchar, MYTH_PROTOCOL_FIELD_SIZE);
    3.27      buffer = g_strnfill (MYTH_PROTOCOL_FIELD_SIZE, ' ');
    3.28 @@ -963,7 +963,7 @@
    3.29  		//}
    3.30      }  
    3.31  
    3.32 -    g_static_mutex_unlock( &mutex );
    3.33 +    //g_static_mutex_unlock( &mutex );
    3.34  
    3.35      gmyth_debug ("[%s] Response received from backend: {%s}\n", __FUNCTION__, buffer);
    3.36