# HG changeset patch # User rosfran # Date 1171052891 0 # Node ID 2dea9369a985e53dbb5a5ccab1b15c3219010a12 # Parent b00705a84ffedb3623f661b6883cf7c93f4a2342 [svn r345] Fixes for clsing socket connections. diff -r b00705a84ffe -r 2dea9369a985 gmyth/src/gmyth_file_transfer.c --- a/gmyth/src/gmyth_file_transfer.c Thu Feb 08 23:07:59 2007 +0000 +++ b/gmyth/src/gmyth_file_transfer.c Fri Feb 09 20:28:11 2007 +0000 @@ -252,7 +252,7 @@ gboolean ret = TRUE; g_return_val_if_fail (transfer != NULL, FALSE); - g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE); if (transfer->filename != NULL) { @@ -260,7 +260,7 @@ transfer->filename = NULL; } - transfer->filename = g_strdup (filename); + transfer->filename = g_strdup( filename ); /* configure the control socket */ if (transfer->control_sock == NULL) { diff -r b00705a84ffe -r 2dea9369a985 gmyth/src/gmyth_livetv.c --- a/gmyth/src/gmyth_livetv.c Thu Feb 08 23:07:59 2007 +0000 +++ b/gmyth/src/gmyth_livetv.c Fri Feb 09 20:28:11 2007 +0000 @@ -290,21 +290,22 @@ { gboolean res = TRUE; - if ( NULL == livetv->socket ) + livetv->backend_info = backend_info; + + //if ( NULL == livetv->socket ) { livetv->socket = gmyth_socket_new (); + + /* FIME: Implement this at gmyth_socket */ + res = gmyth_socket_connect_to_backend (livetv->socket, livetv->backend_info->hostname, + livetv->backend_info->port, TRUE); + if (!res) { + g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__); + res = FALSE; + goto error; + } + //} - livetv->backend_info = backend_info; - - //g_static_mutex_lock( &lock ); - - /* FIME: Implement this at gmyth_socket */ - res = gmyth_socket_connect_to_backend (livetv->socket, livetv->backend_info->hostname, - livetv->backend_info->port, TRUE); - if (!res) { - g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__); - res = FALSE; - goto error; - } + g_static_mutex_lock( &lock ); livetv->is_livetv = TRUE; @@ -323,7 +324,7 @@ /* Gets the recorder num */ livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1); - //gmyth_socket_close_connection (socket); + gmyth_socket_close_connection (livetv->socket); if ( NULL == livetv->recorder ) { g_warning ("[%s] None remote encoder available", __FUNCTION__); @@ -388,7 +389,7 @@ } /* if - changes the channel number */ - sleep (6); /* FIXME: this is evil (tpm) */ + sleep (8); /* FIXME: this is evil (tpm) */ } /* DEBUG message */ @@ -426,8 +427,10 @@ gmyth_debug( "New ProgramInfo...\n" ); gmyth_program_info_print( prog_info ); /* DEBUG message */ + /* gmyth_debug( "Old ProgramInfo...\n" ); gmyth_program_info_print( livetv->proginfo ); + */ /* GMythProgramInfo* prog_inf = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_UP ); @@ -470,7 +473,7 @@ livetv->uri = (GMythURI*)gmyth_backend_info_get_uri( backend_info ); - //g_static_mutex_unlock( &lock ); + g_static_mutex_unlock( &lock ); if ( !gmyth_livetv_monitor_handler_start( livetv ) ) { diff -r b00705a84ffe -r 2dea9369a985 gmyth/src/gmyth_monitor_handler.c --- a/gmyth/src/gmyth_monitor_handler.c Thu Feb 08 23:07:59 2007 +0000 +++ b/gmyth/src/gmyth_monitor_handler.c Fri Feb 09 20:28:11 2007 +0000 @@ -84,7 +84,7 @@ static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message ); -static GMutex* mutex = NULL; +static GStaticMutex mutex = G_STATIC_MUTEX_INIT; //static GCond* io_watcher_cond = NULL; @@ -147,7 +147,7 @@ //io_watcher_cond = g_cond_new(); /* mutex to control access to the event socket consumer thread */ - //mutex = g_mutex_new(); + /*monitor->mutex = g_mutex_new();*/ monitor->monitor_th = NULL; @@ -167,15 +167,15 @@ { g_thread_pool_free( monitor->monitor_th, TRUE, FALSE ); //g_thread_exit( monitor->monitor_th ); - /*if ( monitor->monitor_th != NULL ) - g_object_unref( monitor->monitor_th );*/ + //if ( monitor->monitor_th != NULL ) + // g_object_unref( monitor->monitor_th ); monitor->monitor_th = NULL; } if ( monitor->event_sock != NULL ) { g_object_unref( monitor->event_sock ); - gmyth_socket_close_connection( monitor->event_sock ); + /*gmyth_socket_close_connection( monitor->event_sock );*/ monitor->event_sock = NULL; } @@ -191,11 +191,13 @@ monitor->backend_msgs = NULL; } - if ( mutex != NULL ) + /* + if ( monitor->mutex != NULL ) { - g_mutex_free( mutex ); - mutex = NULL; + g_mutex_free( monitor->mutex ); + monitor->mutex = NULL; } + */ /* if ( io_watcher_cond != NULL ) @@ -220,20 +222,20 @@ GMythMonitorHandler* gmyth_monitor_handler_new ( void ) { - GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( g_object_new ( GMYTH_MONITOR_HANDLER_TYPE, - FALSE ) ); + GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( + g_object_new ( GMYTH_MONITOR_HANDLER_TYPE, FALSE ) ); return monitor; } static gboolean -myth_control_acquire_context( gboolean do_wait ) +myth_control_acquire_context( GMythMonitorHandler *monitor, gboolean do_wait ) { gboolean ret = TRUE; //guint max_iter = 50; - //g_mutex_lock( mutex ); + //g_mutex_lock( monitor->mutex ); //while ( !has_io_access ) // g_cond_wait( io_watcher_cond, mutex ); @@ -247,19 +249,19 @@ ret = FALSE; */ - //g_static_mutex_lock( &st_mutex ); + g_static_mutex_lock( &mutex ); return ret; } static gboolean -myth_control_release_context( ) +myth_control_release_context( GMythMonitorHandler *monitor ) { gboolean ret = TRUE; - //g_static_mutex_unlock( &st_mutex ); + g_static_mutex_unlock( &mutex ); //g_main_context_release( io_watcher_context ); @@ -269,7 +271,7 @@ //g_cond_broadcast( io_watcher_cond ); - //g_mutex_unlock( mutex ); + //g_mutex_unlock( monitor->mutex ); return ret; @@ -279,7 +281,8 @@ gmyth_monitor_handler_close (GMythMonitorHandler *monitor) { monitor->allow_msgs_listener = FALSE; - + +#if 0 if ( monitor->monitor_th != NULL ) { g_thread_pool_free( monitor->monitor_th, TRUE, FALSE ); @@ -293,6 +296,8 @@ { gmyth_socket_close_connection( monitor->event_sock ); } +#endif + } gboolean @@ -333,38 +338,46 @@ gint msg_type = GMYTH_BACKEND_NO_MESSAGE; GString *back_msg = NULL; - back_msg = gmyth_string_list_get_string( strlist, 0 ); - if ( back_msg != NULL && back_msg->str != NULL && - strstr( back_msg->str, "BACKEND" ) != NULL ) + if ( gmyth_string_list_length(strlist) > 0 ) { - gmyth_debug( "MONITOR HANDLER - Received backend message = %s", back_msg->str ); - *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 ); - - if ( back_msg_action != NULL ) - { - - if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) || - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) || - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "SCHEDULE_CHANGE" ) || - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) ) - { - gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s", *back_msg_action ); - msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED; - } else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "DONE_RECORDING" ) ) { - gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s", *back_msg_action ); - msg_type = GMYTH_BACKEND_DONE_RECORDING; - } - - //g_hash_table_insert ( monitor->backend_msgs, - // &(monitor->actual_index), *back_msg_action ); - - } // if - } + + back_msg = gmyth_string_list_get_string( strlist, 0 ); + if ( back_msg != NULL && back_msg->str != NULL && + strstr( back_msg->str, "BACKEND" ) != NULL ) + { + gmyth_debug( "MONITOR HANDLER - Received backend message = %s", back_msg->str ); + *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 ); + + if ( back_msg_action != NULL ) + { + + if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) || + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) || + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "SCHEDULE_CHANGE" ) || + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) ) + { + gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s", *back_msg_action ); + msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED; + } else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "DONE_RECORDING" ) ) { + gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s", *back_msg_action ); + msg_type = GMYTH_BACKEND_DONE_RECORDING; + } - if ( back_msg != NULL ) - { - g_string_free( back_msg, TRUE ); - back_msg = NULL; + //g_hash_table_insert ( monitor->backend_msgs, + // &(monitor->actual_index), *back_msg_action ); + + } // if + } + + if ( back_msg != NULL ) + { + g_string_free( back_msg, TRUE ); + back_msg = NULL; + } + + } /* if - Does Monitor got any message from backend? */ + else { + *back_msg_action = g_strdup(""); } return msg_type; @@ -411,7 +424,7 @@ //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data; - myth_control_acquire_context (TRUE); + myth_control_acquire_context (monitor, TRUE); if ( io_channel == NULL ) { g_debug ("Monitor socket is NULL!\n"); @@ -451,7 +464,8 @@ gchar *back_msg_action = g_new0( gchar, 1 ); gint msg_type = gmyth_monitor_handler_is_backend_message( monitor, strlist, &back_msg_action ); - + + if (monitor!=NULL) g_signal_emit ( monitor, GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id, 0, /* details */ @@ -477,7 +491,7 @@ } /* main GThread while */ - myth_control_release_context (); + myth_control_release_context (monitor); if ( io_status == G_IO_STATUS_ERROR ) { //gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" ); diff -r b00705a84ffe -r 2dea9369a985 gmyth/src/gmyth_monitor_handler.h --- a/gmyth/src/gmyth_monitor_handler.h Thu Feb 08 23:07:59 2007 +0000 +++ b/gmyth/src/gmyth_monitor_handler.h Fri Feb 09 20:28:11 2007 +0000 @@ -99,6 +99,8 @@ /* stores the messages coming from the backend */ GHashTable *backend_msgs; + + /*GMutex *mutex;*/ }; diff -r b00705a84ffe -r 2dea9369a985 gmyth/src/gmyth_recorder.c --- a/gmyth/src/gmyth_recorder.c Thu Feb 08 23:07:59 2007 +0000 +++ b/gmyth/src/gmyth_recorder.c Fri Feb 09 20:28:11 2007 +0000 @@ -70,7 +70,7 @@ { GMythRecorder *recorder = GMYTH_RECORDER(object); - gmyth_recorder_close(recorder); + //gmyth_recorder_close(recorder); if ( recorder->myth_socket != NULL ) { g_object_unref (recorder->myth_socket); diff -r b00705a84ffe -r 2dea9369a985 gmyth/src/gmyth_socket.c --- a/gmyth/src/gmyth_socket.c Thu Feb 08 23:07:59 2007 +0000 +++ b/gmyth/src/gmyth_socket.c Fri Feb 09 20:28:11 2007 +0000 @@ -67,7 +67,7 @@ #define MYTHTV_MAX_VERSION_CHECKS 40 // FIXME: put this in the right place -#define MYTHTV_VERSION_DEFAULT 30 +#define MYTHTV_VERSION_DEFAULT 31 static GStaticMutex mutex = G_STATIC_MUTEX_INIT; @@ -278,7 +278,7 @@ if ( err == EADDRNOTAVAIL ) { - g_warning( "[%s] Address (%s) not available. (reason = %d)\n", __FUNCTION__, localhostname, err ); + g_debug( "[%s] Address (%s) not available. (reason = %d)\n", __FUNCTION__, localhostname, err ); return str; } @@ -313,7 +313,7 @@ gchar *prim_addr = gmyth_socket_get_primary_addr(); if ( prim_addr != NULL ) { - g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n", + g_debug("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n", __FUNCTION__, prim_addr ); str = g_string_new (prim_addr); @@ -340,8 +340,8 @@ /* disconnect socket */ gmyth_socket_close_connection (gmyth_socket); - //g_free (gmyth_socket->hostname); - //gmyth_socket->hostname = NULL; + g_free (gmyth_socket->hostname); + gmyth_socket->hostname = NULL; g_free (local_hostname); @@ -392,14 +392,14 @@ saveflags = fcntl( fd, F_GETFL, 0 ); if( saveflags < 0 ) { - g_warning( "[%s] Problems when getting socket flags on fcntl.\n", __FUNCTION__ ); + g_debug( "[%s] Problems when getting socket flags on fcntl.\n", __FUNCTION__ ); *err=errno; return -1; } /* Set non blocking */ if( fcntl( fd, F_SETFL, saveflags | O_NONBLOCK ) < 0) { - g_warning( "[%s] Problems when setting non-blocking using fcntl.\n", __FUNCTION__ ); + g_debug( "[%s] Problems when setting non-blocking using fcntl.\n", __FUNCTION__ ); *err=errno; return -1; } @@ -410,7 +410,7 @@ /* restore flags */ if( fcntl( fd, F_SETFL, saveflags ) < 0) { - g_warning( "[%s] Problems when trying to restore flags with fcntl.\n", __FUNCTION__ ); + g_debug( "[%s] Problems when trying to restore flags with fcntl.\n", __FUNCTION__ ); *err=errno; return -1; } @@ -418,7 +418,7 @@ /* return unless the connection was successful or the connect is still in progress. */ if( *err < 0 && back_err != EINPROGRESS) { - g_warning( "[%s] Connection unsucessfully (it is not in progress).\n", __FUNCTION__ ); + g_debug( "[%s] Connection unsucessfully (it is not in progress).\n", __FUNCTION__ ); *err = errno; return -1; } @@ -428,13 +428,15 @@ *err = select( FD_SETSIZE, NULL, &fd_w, NULL, timeout); if ( *err < 0 ) { - g_warning( "[%s] Connection unsucessfull (timed out).\n", __FUNCTION__ ); + g_debug( "[%s] Connection unsucessfull (timed out).\n", __FUNCTION__ ); *err=errno; return -1; } /* 0 means it timeout out & no fds changed */ if(*err==0) { + g_debug( "[%s] Connection unsucessfull [%d] - 0 means it timeout out & no fds changed\n", + __FUNCTION__, *err ); close(fd); *err=ETIMEDOUT; return -1; @@ -445,13 +447,14 @@ *err=getsockopt( fd, SOL_SOCKET, SO_ERROR, &ret, (socklen_t *) &len); if( *err < 0 ) { - g_warning( "[%s] Connection usnsucessfull.\n", __FUNCTION__ ); + g_debug( "[%s] Connection unsucessfull.\n", __FUNCTION__ ); *err=errno; return -1; } /* ret=0 means success, otherwise it contains the errno */ if (ret) { + g_debug( "[%s] Connection unsucessfull - Couldn't connect to remote host!!!\n", __FUNCTION__ ); *err=ret; return -1; } @@ -482,7 +485,7 @@ const gchar *hostname, gint port, guint timeout) { struct addrinfo *addr_info_data = NULL, *addr_info0 = NULL; - gint ret_code = -1; + gint ret_code = 0; /* -1 */ gint errno; gboolean ret = TRUE; @@ -550,19 +553,29 @@ g_io_channel_unref (gmyth_socket->sd_io_ch); gmyth_socket->sd_io_ch = NULL; } - + + struct linger* ling = g_malloc0( sizeof(struct linger) ); + ling->l_onoff = TRUE; + ling->l_linger = 1; + + setsockopt(gmyth_socket->sd, SOL_SOCKET, SO_LINGER, ling, sizeof(struct linger)); + gmyth_socket->sd_io_ch = g_io_channel_unix_new (gmyth_socket->sd); - g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE); + //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); + 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 ; + if ( !ret ) + gmyth_debug("GMythSocket error - return code error!"); + return ret; } @@ -592,7 +605,7 @@ GIOCondition io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); if ( ( io_cond & G_IO_IN ) == 0 ) { - g_warning ("[%s] IO channel is not able to send data!\n", __FUNCTION__); + g_debug ("[%s] IO channel is not able to send data!\n", __FUNCTION__); ret = FALSE; } @@ -614,7 +627,7 @@ GIOCondition io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); if ( ( ( io_cond & G_IO_OUT ) == 0 ) || ( ( io_cond & G_IO_HUP ) == 0 ) ) { - g_warning ("[%s] IO channel is not able to send data!\n", __FUNCTION__); + g_debug ("[%s] IO channel is not able to send data!\n", __FUNCTION__); ret = FALSE; } @@ -634,20 +647,21 @@ GIOStatus io_status = G_IO_STATUS_NORMAL; //GIOCondition io_cond; - GError* error = NULL; - + GError* error = NULL; gchar *buffer = NULL; gsize bytes_written = 0; + + g_return_val_if_fail( gmyth_socket->sd_io_ch != NULL, FALSE ); if( command == NULL || ( command->len <= 0 ) || command->str == NULL ) { - g_warning ("[%s] Invalid NULL command parameter!\n", __FUNCTION__); + g_debug ("[%s] Invalid NULL command parameter!\n", __FUNCTION__); ret = FALSE; goto done; } - //g_static_mutex_lock( &mutex ); + g_static_mutex_lock( &mutex ); gmyth_debug ("Sending command to backend: %s\n", command->str); buffer = g_strnfill( BUFLEN, ' ' ); @@ -661,10 +675,10 @@ if( (io_status == G_IO_STATUS_ERROR) || ( bytes_written <= 0 ) ) { - g_warning ("[%s] Error while writing to socket", __FUNCTION__); + g_debug ("[%s] Error while writing to socket", __FUNCTION__); ret = FALSE; } else if ( bytes_written < command->len ) { - g_warning ("[%s] Not all data was written socket", __FUNCTION__); + g_debug ("[%s] Not all data was written socket", __FUNCTION__); ret = FALSE; } @@ -672,12 +686,12 @@ if ( ( bytes_written != command->len ) || ( io_status == G_IO_STATUS_ERROR ) ) { - g_warning ("[%s] Some problem occurred when sending data to the socket\n", __FUNCTION__); + g_debug ("[%s] Some problem occurred when sending data to the socket\n", __FUNCTION__); ret = TRUE; } - //g_static_mutex_unlock( &mutex ); + g_static_mutex_unlock( &mutex ); done: if ( error != NULL ) { g_printerr( "[%s] Error found reading data from IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message ); @@ -707,7 +721,7 @@ gboolean with_events) { if (!gmyth_socket_connect (gmyth_socket, hostname_backend, port)) { - g_warning ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__, + g_debug ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__, hostname_backend ); return FALSE; } @@ -741,7 +755,7 @@ return TRUE; } else { - g_warning ("[%s] GMythSocket could not connect to the backend", __FUNCTION__); + g_debug ("[%s] GMythSocket could not connect to the backend", __FUNCTION__); return FALSE; } } @@ -798,16 +812,20 @@ void gmyth_socket_close_connection (GMythSocket *gmyth_socket) { - //if ( gmyth_socket->sd != -1 ) { - // close (gmyth_socket->sd); - //gmyth_socket->sd = -1; - //} + /* + if ( gmyth_socket->sd != -1 ) { + close (gmyth_socket->sd); + gmyth_socket->sd = -1; + } + */ if (gmyth_socket->sd_io_ch != NULL) { - g_io_channel_shutdown (gmyth_socket->sd_io_ch, TRUE, NULL); - //g_io_channel_unref (gmyth_socket->sd_io_ch); - //gmyth_socket->sd_io_ch = NULL; + //g_io_channel_shutdown (gmyth_socket->sd_io_ch, TRUE, NULL); + g_io_channel_unref (gmyth_socket->sd_io_ch); + gmyth_socket->sd_io_ch = NULL; + gmyth_socket->sd = -1; } + } @@ -837,14 +855,14 @@ response = gmyth_socket_receive_response(gmyth_socket); if (response == NULL) { - g_warning ("[%s] Check protocol version error! Not answered!", __FUNCTION__); + g_debug ("[%s] Check protocol version error! Not answered!", __FUNCTION__); res = FALSE; goto done; } res = g_str_has_prefix (response->str, "ACCEPT"); if (!res) { - g_warning ("[%s] Protocol version request error: %s", __FUNCTION__, response->str); + g_debug ("[%s] Protocol version request error: %s", __FUNCTION__, response->str); /* get the version number returned by the REJECT message */ if ( ( res = g_str_has_prefix (response->str, "REJECT") ) == TRUE ) { gchar *new_version = NULL; @@ -939,7 +957,7 @@ gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port ); } - if ( gmyth_socket->sd_io_ch->is_readable ) + 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(""); @@ -953,7 +971,7 @@ gmyth_debug ( "[%s] Bytes read = %d\n", __FUNCTION__, bytes_read ); if( (io_status == G_IO_STATUS_ERROR) || (bytes_read <= 0) ) { - g_warning ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__); + g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__); str = NULL; //return NULL; } else { @@ -962,7 +980,7 @@ /* verify if the input (read) buffer is ready to receive data */ io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch ); - if ( ( io_cond & G_IO_IN ) != 0 ) { + //if ( ( io_cond & G_IO_IN ) != 0 ) { //gchar *buffer_aux = NULL; /* removes trailing whitespace */ @@ -992,7 +1010,7 @@ return g_string_new(""); buffer[bytes_read] = '\0'; - } + //} } //g_static_mutex_unlock( &mutex ); @@ -1078,15 +1096,20 @@ gint i; response = gmyth_socket_receive_response(gmyth_socket); - g_static_mutex_lock( &mutex ); - - gmyth_string_list_clear_all (str_list); - str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1); - - for (i=0; i< g_strv_length (str_array); i++) { - gmyth_string_list_append_char_array (str_list, str_array[i] ); + if ( response != NULL && response->str != NULL && response->len > 0 ) + { + + g_static_mutex_lock( &mutex ); + + gmyth_string_list_clear_all (str_list); + str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1); + + for (i=0; i< g_strv_length (str_array); i++) { + gmyth_string_list_append_char_array (str_list, str_array[i] ); + } + g_static_mutex_unlock( &mutex ); + } - g_static_mutex_unlock( &mutex ); g_string_free (response, TRUE); g_strfreev (str_array);