[svn r345] Fixes for clsing socket connections.
1.1 --- a/gmyth/src/gmyth_file_transfer.c Thu Feb 08 23:07:59 2007 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Fri Feb 09 20:28:11 2007 +0000
1.3 @@ -252,7 +252,7 @@
1.4 gboolean ret = TRUE;
1.5
1.6 g_return_val_if_fail (transfer != NULL, FALSE);
1.7 - g_return_val_if_fail (filename != NULL, FALSE);
1.8 + g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
1.9
1.10 if (transfer->filename != NULL)
1.11 {
1.12 @@ -260,7 +260,7 @@
1.13 transfer->filename = NULL;
1.14 }
1.15
1.16 - transfer->filename = g_strdup (filename);
1.17 + transfer->filename = g_strdup( filename );
1.18
1.19 /* configure the control socket */
1.20 if (transfer->control_sock == NULL) {
2.1 --- a/gmyth/src/gmyth_livetv.c Thu Feb 08 23:07:59 2007 +0000
2.2 +++ b/gmyth/src/gmyth_livetv.c Fri Feb 09 20:28:11 2007 +0000
2.3 @@ -290,21 +290,22 @@
2.4 {
2.5 gboolean res = TRUE;
2.6
2.7 - if ( NULL == livetv->socket )
2.8 + livetv->backend_info = backend_info;
2.9 +
2.10 + //if ( NULL == livetv->socket ) {
2.11 livetv->socket = gmyth_socket_new ();
2.12 +
2.13 + /* FIME: Implement this at gmyth_socket */
2.14 + res = gmyth_socket_connect_to_backend (livetv->socket, livetv->backend_info->hostname,
2.15 + livetv->backend_info->port, TRUE);
2.16 + if (!res) {
2.17 + g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);
2.18 + res = FALSE;
2.19 + goto error;
2.20 + }
2.21 + //}
2.22
2.23 - livetv->backend_info = backend_info;
2.24 -
2.25 - //g_static_mutex_lock( &lock );
2.26 -
2.27 - /* FIME: Implement this at gmyth_socket */
2.28 - res = gmyth_socket_connect_to_backend (livetv->socket, livetv->backend_info->hostname,
2.29 - livetv->backend_info->port, TRUE);
2.30 - if (!res) {
2.31 - g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);
2.32 - res = FALSE;
2.33 - goto error;
2.34 - }
2.35 + g_static_mutex_lock( &lock );
2.36
2.37 livetv->is_livetv = TRUE;
2.38
2.39 @@ -323,7 +324,7 @@
2.40
2.41 /* Gets the recorder num */
2.42 livetv->recorder = remote_request_next_free_recorder (livetv->socket, -1);
2.43 - //gmyth_socket_close_connection (socket);
2.44 + gmyth_socket_close_connection (livetv->socket);
2.45
2.46 if ( NULL == livetv->recorder ) {
2.47 g_warning ("[%s] None remote encoder available", __FUNCTION__);
2.48 @@ -388,7 +389,7 @@
2.49
2.50 } /* if - changes the channel number */
2.51
2.52 - sleep (6); /* FIXME: this is evil (tpm) */
2.53 + sleep (8); /* FIXME: this is evil (tpm) */
2.54 }
2.55
2.56 /* DEBUG message */
2.57 @@ -426,8 +427,10 @@
2.58 gmyth_debug( "New ProgramInfo...\n" );
2.59 gmyth_program_info_print( prog_info );
2.60 /* DEBUG message */
2.61 + /*
2.62 gmyth_debug( "Old ProgramInfo...\n" );
2.63 gmyth_program_info_print( livetv->proginfo );
2.64 + */
2.65
2.66 /*
2.67 GMythProgramInfo* prog_inf = gmyth_recorder_get_next_program_info( livetv->recorder, BROWSE_DIRECTION_UP );
2.68 @@ -470,7 +473,7 @@
2.69
2.70 livetv->uri = (GMythURI*)gmyth_backend_info_get_uri( backend_info );
2.71
2.72 - //g_static_mutex_unlock( &lock );
2.73 + g_static_mutex_unlock( &lock );
2.74
2.75 if ( !gmyth_livetv_monitor_handler_start( livetv ) )
2.76 {
3.1 --- a/gmyth/src/gmyth_monitor_handler.c Thu Feb 08 23:07:59 2007 +0000
3.2 +++ b/gmyth/src/gmyth_monitor_handler.c Fri Feb 09 20:28:11 2007 +0000
3.3 @@ -84,7 +84,7 @@
3.4
3.5 static void gmyth_monitor_handler_default_listener( GMythMonitorHandler *monitor, gint msg_code, gchar* message );
3.6
3.7 -static GMutex* mutex = NULL;
3.8 +static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
3.9
3.10 //static GCond* io_watcher_cond = NULL;
3.11
3.12 @@ -147,7 +147,7 @@
3.13 //io_watcher_cond = g_cond_new();
3.14
3.15 /* mutex to control access to the event socket consumer thread */
3.16 - //mutex = g_mutex_new();
3.17 + /*monitor->mutex = g_mutex_new();*/
3.18
3.19 monitor->monitor_th = NULL;
3.20
3.21 @@ -167,15 +167,15 @@
3.22 {
3.23 g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
3.24 //g_thread_exit( monitor->monitor_th );
3.25 - /*if ( monitor->monitor_th != NULL )
3.26 - g_object_unref( monitor->monitor_th );*/
3.27 + //if ( monitor->monitor_th != NULL )
3.28 + // g_object_unref( monitor->monitor_th );
3.29 monitor->monitor_th = NULL;
3.30 }
3.31
3.32 if ( monitor->event_sock != NULL )
3.33 {
3.34 g_object_unref( monitor->event_sock );
3.35 - gmyth_socket_close_connection( monitor->event_sock );
3.36 + /*gmyth_socket_close_connection( monitor->event_sock );*/
3.37 monitor->event_sock = NULL;
3.38 }
3.39
3.40 @@ -191,11 +191,13 @@
3.41 monitor->backend_msgs = NULL;
3.42 }
3.43
3.44 - if ( mutex != NULL )
3.45 + /*
3.46 + if ( monitor->mutex != NULL )
3.47 {
3.48 - g_mutex_free( mutex );
3.49 - mutex = NULL;
3.50 + g_mutex_free( monitor->mutex );
3.51 + monitor->mutex = NULL;
3.52 }
3.53 + */
3.54
3.55 /*
3.56 if ( io_watcher_cond != NULL )
3.57 @@ -220,20 +222,20 @@
3.58 GMythMonitorHandler*
3.59 gmyth_monitor_handler_new ( void )
3.60 {
3.61 - GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER ( g_object_new ( GMYTH_MONITOR_HANDLER_TYPE,
3.62 - FALSE ) );
3.63 + GMythMonitorHandler *monitor = GMYTH_MONITOR_HANDLER (
3.64 + g_object_new ( GMYTH_MONITOR_HANDLER_TYPE, FALSE ) );
3.65
3.66 return monitor;
3.67 }
3.68
3.69 static gboolean
3.70 -myth_control_acquire_context( gboolean do_wait )
3.71 +myth_control_acquire_context( GMythMonitorHandler *monitor, gboolean do_wait )
3.72 {
3.73
3.74 gboolean ret = TRUE;
3.75 //guint max_iter = 50;
3.76
3.77 - //g_mutex_lock( mutex );
3.78 + //g_mutex_lock( monitor->mutex );
3.79
3.80 //while ( !has_io_access )
3.81 // g_cond_wait( io_watcher_cond, mutex );
3.82 @@ -247,19 +249,19 @@
3.83 ret = FALSE;
3.84 */
3.85
3.86 - //g_static_mutex_lock( &st_mutex );
3.87 + g_static_mutex_lock( &mutex );
3.88
3.89 return ret;
3.90
3.91 }
3.92
3.93 static gboolean
3.94 -myth_control_release_context( )
3.95 +myth_control_release_context( GMythMonitorHandler *monitor )
3.96 {
3.97
3.98 gboolean ret = TRUE;
3.99
3.100 - //g_static_mutex_unlock( &st_mutex );
3.101 + g_static_mutex_unlock( &mutex );
3.102
3.103 //g_main_context_release( io_watcher_context );
3.104
3.105 @@ -269,7 +271,7 @@
3.106
3.107 //g_cond_broadcast( io_watcher_cond );
3.108
3.109 - //g_mutex_unlock( mutex );
3.110 + //g_mutex_unlock( monitor->mutex );
3.111
3.112 return ret;
3.113
3.114 @@ -279,7 +281,8 @@
3.115 gmyth_monitor_handler_close (GMythMonitorHandler *monitor)
3.116 {
3.117 monitor->allow_msgs_listener = FALSE;
3.118 -
3.119 +
3.120 +#if 0
3.121 if ( monitor->monitor_th != NULL )
3.122 {
3.123 g_thread_pool_free( monitor->monitor_th, TRUE, FALSE );
3.124 @@ -293,6 +296,8 @@
3.125 {
3.126 gmyth_socket_close_connection( monitor->event_sock );
3.127 }
3.128 +#endif
3.129 +
3.130 }
3.131
3.132 gboolean
3.133 @@ -333,38 +338,46 @@
3.134 gint msg_type = GMYTH_BACKEND_NO_MESSAGE;
3.135 GString *back_msg = NULL;
3.136
3.137 - back_msg = gmyth_string_list_get_string( strlist, 0 );
3.138 - if ( back_msg != NULL && back_msg->str != NULL &&
3.139 - strstr( back_msg->str, "BACKEND" ) != NULL )
3.140 + if ( gmyth_string_list_length(strlist) > 0 )
3.141 {
3.142 - gmyth_debug( "MONITOR HANDLER - Received backend message = %s", back_msg->str );
3.143 - *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );
3.144 -
3.145 - if ( back_msg_action != NULL )
3.146 - {
3.147 -
3.148 - if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
3.149 - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
3.150 - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "SCHEDULE_CHANGE" ) ||
3.151 - g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
3.152 - {
3.153 - gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s", *back_msg_action );
3.154 - msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
3.155 - } else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "DONE_RECORDING" ) ) {
3.156 - gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s", *back_msg_action );
3.157 - msg_type = GMYTH_BACKEND_DONE_RECORDING;
3.158 - }
3.159 -
3.160 - //g_hash_table_insert ( monitor->backend_msgs,
3.161 - // &(monitor->actual_index), *back_msg_action );
3.162 -
3.163 - } // if
3.164 - }
3.165 +
3.166 + back_msg = gmyth_string_list_get_string( strlist, 0 );
3.167 + if ( back_msg != NULL && back_msg->str != NULL &&
3.168 + strstr( back_msg->str, "BACKEND" ) != NULL )
3.169 + {
3.170 + gmyth_debug( "MONITOR HANDLER - Received backend message = %s", back_msg->str );
3.171 + *back_msg_action = gmyth_string_list_get_char_array( strlist, 1 );
3.172 +
3.173 + if ( back_msg_action != NULL )
3.174 + {
3.175 +
3.176 + if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_CHAIN" ) ||
3.177 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "RECORDING_LIST_CHANGE" ) ||
3.178 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "SCHEDULE_CHANGE" ) ||
3.179 + g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "LIVETV_WATCH" ) )
3.180 + {
3.181 + gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_PROGRAM_INFO_CHANGED, msg = %s", *back_msg_action );
3.182 + msg_type = GMYTH_BACKEND_PROGRAM_INFO_CHANGED;
3.183 + } else if ( g_strstr_len( *back_msg_action, strlen( *back_msg_action ), "DONE_RECORDING" ) ) {
3.184 + gmyth_debug( "MONITOR: message type == GMYTH_BACKEND_DONE_RECORDING, msg = %s", *back_msg_action );
3.185 + msg_type = GMYTH_BACKEND_DONE_RECORDING;
3.186 + }
3.187
3.188 - if ( back_msg != NULL )
3.189 - {
3.190 - g_string_free( back_msg, TRUE );
3.191 - back_msg = NULL;
3.192 + //g_hash_table_insert ( monitor->backend_msgs,
3.193 + // &(monitor->actual_index), *back_msg_action );
3.194 +
3.195 + } // if
3.196 + }
3.197 +
3.198 + if ( back_msg != NULL )
3.199 + {
3.200 + g_string_free( back_msg, TRUE );
3.201 + back_msg = NULL;
3.202 + }
3.203 +
3.204 + } /* if - Does Monitor got any message from backend? */
3.205 + else {
3.206 + *back_msg_action = g_strdup("");
3.207 }
3.208
3.209 return msg_type;
3.210 @@ -411,7 +424,7 @@
3.211
3.212 //GMythMonitorHandler *monitor = (GMythMonitorHandler*)data;
3.213
3.214 - myth_control_acquire_context (TRUE);
3.215 + myth_control_acquire_context (monitor, TRUE);
3.216
3.217 if ( io_channel == NULL ) {
3.218 g_debug ("Monitor socket is NULL!\n");
3.219 @@ -451,7 +464,8 @@
3.220 gchar *back_msg_action = g_new0( gchar, 1 );
3.221 gint msg_type = gmyth_monitor_handler_is_backend_message( monitor, strlist,
3.222 &back_msg_action );
3.223 -
3.224 +
3.225 + if (monitor!=NULL)
3.226 g_signal_emit ( monitor,
3.227 GMYTH_MONITOR_HANDLER_GET_CLASS (monitor)->backend_events_handler_signal_id,
3.228 0, /* details */
3.229 @@ -477,7 +491,7 @@
3.230
3.231 } /* main GThread while */
3.232
3.233 - myth_control_release_context ();
3.234 + myth_control_release_context (monitor);
3.235
3.236 if ( io_status == G_IO_STATUS_ERROR ) {
3.237 //gmyth_debug ("[%s] Error reading: %s\n", __FUNCTION__, error != NULL ? error->message : "" );
4.1 --- a/gmyth/src/gmyth_monitor_handler.h Thu Feb 08 23:07:59 2007 +0000
4.2 +++ b/gmyth/src/gmyth_monitor_handler.h Fri Feb 09 20:28:11 2007 +0000
4.3 @@ -99,6 +99,8 @@
4.4
4.5 /* stores the messages coming from the backend */
4.6 GHashTable *backend_msgs;
4.7 +
4.8 + /*GMutex *mutex;*/
4.9
4.10 };
4.11
5.1 --- a/gmyth/src/gmyth_recorder.c Thu Feb 08 23:07:59 2007 +0000
5.2 +++ b/gmyth/src/gmyth_recorder.c Fri Feb 09 20:28:11 2007 +0000
5.3 @@ -70,7 +70,7 @@
5.4 {
5.5 GMythRecorder *recorder = GMYTH_RECORDER(object);
5.6
5.7 - gmyth_recorder_close(recorder);
5.8 + //gmyth_recorder_close(recorder);
5.9
5.10 if ( recorder->myth_socket != NULL ) {
5.11 g_object_unref (recorder->myth_socket);
6.1 --- a/gmyth/src/gmyth_socket.c Thu Feb 08 23:07:59 2007 +0000
6.2 +++ b/gmyth/src/gmyth_socket.c Fri Feb 09 20:28:11 2007 +0000
6.3 @@ -67,7 +67,7 @@
6.4 #define MYTHTV_MAX_VERSION_CHECKS 40
6.5
6.6 // FIXME: put this in the right place
6.7 -#define MYTHTV_VERSION_DEFAULT 30
6.8 +#define MYTHTV_VERSION_DEFAULT 31
6.9
6.10 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
6.11
6.12 @@ -278,7 +278,7 @@
6.13
6.14 if ( err == EADDRNOTAVAIL )
6.15 {
6.16 - g_warning( "[%s] Address (%s) not available. (reason = %d)\n", __FUNCTION__, localhostname, err );
6.17 + g_debug( "[%s] Address (%s) not available. (reason = %d)\n", __FUNCTION__, localhostname, err );
6.18 return str;
6.19 }
6.20
6.21 @@ -313,7 +313,7 @@
6.22 gchar *prim_addr = gmyth_socket_get_primary_addr();
6.23
6.24 if ( prim_addr != NULL ) {
6.25 - g_warning("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n",
6.26 + g_debug("[%s] Could not determine the local alphanumerical hostname. Setting to %s\n",
6.27 __FUNCTION__, prim_addr );
6.28
6.29 str = g_string_new (prim_addr);
6.30 @@ -340,8 +340,8 @@
6.31 /* disconnect socket */
6.32 gmyth_socket_close_connection (gmyth_socket);
6.33
6.34 - //g_free (gmyth_socket->hostname);
6.35 - //gmyth_socket->hostname = NULL;
6.36 + g_free (gmyth_socket->hostname);
6.37 + gmyth_socket->hostname = NULL;
6.38
6.39 g_free (local_hostname);
6.40
6.41 @@ -392,14 +392,14 @@
6.42
6.43 saveflags = fcntl( fd, F_GETFL, 0 );
6.44 if( saveflags < 0 ) {
6.45 - g_warning( "[%s] Problems when getting socket flags on fcntl.\n", __FUNCTION__ );
6.46 + g_debug( "[%s] Problems when getting socket flags on fcntl.\n", __FUNCTION__ );
6.47 *err=errno;
6.48 return -1;
6.49 }
6.50
6.51 /* Set non blocking */
6.52 if( fcntl( fd, F_SETFL, saveflags | O_NONBLOCK ) < 0) {
6.53 - g_warning( "[%s] Problems when setting non-blocking using fcntl.\n", __FUNCTION__ );
6.54 + g_debug( "[%s] Problems when setting non-blocking using fcntl.\n", __FUNCTION__ );
6.55 *err=errno;
6.56 return -1;
6.57 }
6.58 @@ -410,7 +410,7 @@
6.59
6.60 /* restore flags */
6.61 if( fcntl( fd, F_SETFL, saveflags ) < 0) {
6.62 - g_warning( "[%s] Problems when trying to restore flags with fcntl.\n", __FUNCTION__ );
6.63 + g_debug( "[%s] Problems when trying to restore flags with fcntl.\n", __FUNCTION__ );
6.64 *err=errno;
6.65 return -1;
6.66 }
6.67 @@ -418,7 +418,7 @@
6.68 /* return unless the connection was successful or the connect is
6.69 still in progress. */
6.70 if( *err < 0 && back_err != EINPROGRESS) {
6.71 - g_warning( "[%s] Connection unsucessfully (it is not in progress).\n", __FUNCTION__ );
6.72 + g_debug( "[%s] Connection unsucessfully (it is not in progress).\n", __FUNCTION__ );
6.73 *err = errno;
6.74 return -1;
6.75 }
6.76 @@ -428,13 +428,15 @@
6.77
6.78 *err = select( FD_SETSIZE, NULL, &fd_w, NULL, timeout);
6.79 if ( *err < 0 ) {
6.80 - g_warning( "[%s] Connection unsucessfull (timed out).\n", __FUNCTION__ );
6.81 + g_debug( "[%s] Connection unsucessfull (timed out).\n", __FUNCTION__ );
6.82 *err=errno;
6.83 return -1;
6.84 }
6.85
6.86 /* 0 means it timeout out & no fds changed */
6.87 if(*err==0) {
6.88 + g_debug( "[%s] Connection unsucessfull [%d] - 0 means it timeout out & no fds changed\n",
6.89 + __FUNCTION__, *err );
6.90 close(fd);
6.91 *err=ETIMEDOUT;
6.92 return -1;
6.93 @@ -445,13 +447,14 @@
6.94 *err=getsockopt( fd, SOL_SOCKET, SO_ERROR, &ret, (socklen_t *) &len);
6.95
6.96 if( *err < 0 ) {
6.97 - g_warning( "[%s] Connection usnsucessfull.\n", __FUNCTION__ );
6.98 + g_debug( "[%s] Connection unsucessfull.\n", __FUNCTION__ );
6.99 *err=errno;
6.100 return -1;
6.101 }
6.102
6.103 /* ret=0 means success, otherwise it contains the errno */
6.104 if (ret) {
6.105 + g_debug( "[%s] Connection unsucessfull - Couldn't connect to remote host!!!\n", __FUNCTION__ );
6.106 *err=ret;
6.107 return -1;
6.108 }
6.109 @@ -482,7 +485,7 @@
6.110 const gchar *hostname, gint port, guint timeout)
6.111 {
6.112 struct addrinfo *addr_info_data = NULL, *addr_info0 = NULL;
6.113 - gint ret_code = -1;
6.114 + gint ret_code = 0; /* -1 */
6.115 gint errno;
6.116 gboolean ret = TRUE;
6.117
6.118 @@ -550,19 +553,29 @@
6.119 g_io_channel_unref (gmyth_socket->sd_io_ch);
6.120 gmyth_socket->sd_io_ch = NULL;
6.121 }
6.122 -
6.123 +
6.124 + struct linger* ling = g_malloc0( sizeof(struct linger) );
6.125 + ling->l_onoff = TRUE;
6.126 + ling->l_linger = 1;
6.127 +
6.128 + setsockopt(gmyth_socket->sd, SOL_SOCKET, SO_LINGER, ling, sizeof(struct linger));
6.129 +
6.130 gmyth_socket->sd_io_ch = g_io_channel_unix_new (gmyth_socket->sd);
6.131
6.132 - g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE);
6.133 + //g_io_channel_set_close_on_unref (gmyth_socket->sd_io_ch, TRUE);
6.134 + g_io_channel_set_encoding (gmyth_socket->sd_io_ch, NULL, NULL );
6.135
6.136 - //GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
6.137 + GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
6.138 /* unset the nonblock flag */
6.139 - //flags &= ~G_IO_FLAG_NONBLOCK;
6.140 + flags &= ~G_IO_FLAG_NONBLOCK;
6.141 /* unset the nonblocking stuff for some time, because GNUTLS doesn't like
6.142 * that */
6.143 - //g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
6.144 + g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
6.145
6.146 ret = ( ret_code == 0 ) ? TRUE : FALSE ;
6.147 + if ( !ret )
6.148 + gmyth_debug("GMythSocket error - return code error!");
6.149 +
6.150 return ret;
6.151 }
6.152
6.153 @@ -592,7 +605,7 @@
6.154 GIOCondition io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
6.155
6.156 if ( ( io_cond & G_IO_IN ) == 0 ) {
6.157 - g_warning ("[%s] IO channel is not able to send data!\n", __FUNCTION__);
6.158 + g_debug ("[%s] IO channel is not able to send data!\n", __FUNCTION__);
6.159 ret = FALSE;
6.160 }
6.161
6.162 @@ -614,7 +627,7 @@
6.163 GIOCondition io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
6.164
6.165 if ( ( ( io_cond & G_IO_OUT ) == 0 ) || ( ( io_cond & G_IO_HUP ) == 0 ) ) {
6.166 - g_warning ("[%s] IO channel is not able to send data!\n", __FUNCTION__);
6.167 + g_debug ("[%s] IO channel is not able to send data!\n", __FUNCTION__);
6.168 ret = FALSE;
6.169 }
6.170
6.171 @@ -634,20 +647,21 @@
6.172
6.173 GIOStatus io_status = G_IO_STATUS_NORMAL;
6.174 //GIOCondition io_cond;
6.175 - GError* error = NULL;
6.176 -
6.177 + GError* error = NULL;
6.178
6.179 gchar *buffer = NULL;
6.180
6.181 gsize bytes_written = 0;
6.182 +
6.183 + g_return_val_if_fail( gmyth_socket->sd_io_ch != NULL, FALSE );
6.184
6.185 if( command == NULL || ( command->len <= 0 ) || command->str == NULL ) {
6.186 - g_warning ("[%s] Invalid NULL command parameter!\n", __FUNCTION__);
6.187 + g_debug ("[%s] Invalid NULL command parameter!\n", __FUNCTION__);
6.188 ret = FALSE;
6.189 goto done;
6.190 }
6.191
6.192 - //g_static_mutex_lock( &mutex );
6.193 + g_static_mutex_lock( &mutex );
6.194 gmyth_debug ("Sending command to backend: %s\n", command->str);
6.195
6.196 buffer = g_strnfill( BUFLEN, ' ' );
6.197 @@ -661,10 +675,10 @@
6.198
6.199
6.200 if( (io_status == G_IO_STATUS_ERROR) || ( bytes_written <= 0 ) ) {
6.201 - g_warning ("[%s] Error while writing to socket", __FUNCTION__);
6.202 + g_debug ("[%s] Error while writing to socket", __FUNCTION__);
6.203 ret = FALSE;
6.204 } else if ( bytes_written < command->len ) {
6.205 - g_warning ("[%s] Not all data was written socket", __FUNCTION__);
6.206 + g_debug ("[%s] Not all data was written socket", __FUNCTION__);
6.207 ret = FALSE;
6.208 }
6.209
6.210 @@ -672,12 +686,12 @@
6.211
6.212 if ( ( bytes_written != command->len ) || ( io_status == G_IO_STATUS_ERROR ) )
6.213 {
6.214 - g_warning ("[%s] Some problem occurred when sending data to the socket\n", __FUNCTION__);
6.215 + g_debug ("[%s] Some problem occurred when sending data to the socket\n", __FUNCTION__);
6.216
6.217 ret = TRUE;
6.218 }
6.219
6.220 - //g_static_mutex_unlock( &mutex );
6.221 + g_static_mutex_unlock( &mutex );
6.222 done:
6.223 if ( error != NULL ) {
6.224 g_printerr( "[%s] Error found reading data from IO channel: (%d, %s)\n", __FUNCTION__, error->code, error->message );
6.225 @@ -707,7 +721,7 @@
6.226 gboolean with_events)
6.227 {
6.228 if (!gmyth_socket_connect (gmyth_socket, hostname_backend, port)) {
6.229 - g_warning ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__,
6.230 + g_debug ("[%s] Could not open socket to backend machine [%s]\n", __FUNCTION__,
6.231 hostname_backend );
6.232 return FALSE;
6.233 }
6.234 @@ -741,7 +755,7 @@
6.235
6.236 return TRUE;
6.237 } else {
6.238 - g_warning ("[%s] GMythSocket could not connect to the backend", __FUNCTION__);
6.239 + g_debug ("[%s] GMythSocket could not connect to the backend", __FUNCTION__);
6.240 return FALSE;
6.241 }
6.242 }
6.243 @@ -798,16 +812,20 @@
6.244 void
6.245 gmyth_socket_close_connection (GMythSocket *gmyth_socket)
6.246 {
6.247 - //if ( gmyth_socket->sd != -1 ) {
6.248 - // close (gmyth_socket->sd);
6.249 - //gmyth_socket->sd = -1;
6.250 - //}
6.251 + /*
6.252 + if ( gmyth_socket->sd != -1 ) {
6.253 + close (gmyth_socket->sd);
6.254 + gmyth_socket->sd = -1;
6.255 + }
6.256 + */
6.257
6.258 if (gmyth_socket->sd_io_ch != NULL) {
6.259 - g_io_channel_shutdown (gmyth_socket->sd_io_ch, TRUE, NULL);
6.260 - //g_io_channel_unref (gmyth_socket->sd_io_ch);
6.261 - //gmyth_socket->sd_io_ch = NULL;
6.262 + //g_io_channel_shutdown (gmyth_socket->sd_io_ch, TRUE, NULL);
6.263 + g_io_channel_unref (gmyth_socket->sd_io_ch);
6.264 + gmyth_socket->sd_io_ch = NULL;
6.265 + gmyth_socket->sd = -1;
6.266 }
6.267 +
6.268 }
6.269
6.270
6.271 @@ -837,14 +855,14 @@
6.272 response = gmyth_socket_receive_response(gmyth_socket);
6.273
6.274 if (response == NULL) {
6.275 - g_warning ("[%s] Check protocol version error! Not answered!", __FUNCTION__);
6.276 + g_debug ("[%s] Check protocol version error! Not answered!", __FUNCTION__);
6.277 res = FALSE;
6.278 goto done;
6.279 }
6.280
6.281 res = g_str_has_prefix (response->str, "ACCEPT");
6.282 if (!res) {
6.283 - g_warning ("[%s] Protocol version request error: %s", __FUNCTION__, response->str);
6.284 + g_debug ("[%s] Protocol version request error: %s", __FUNCTION__, response->str);
6.285 /* get the version number returned by the REJECT message */
6.286 if ( ( res = g_str_has_prefix (response->str, "REJECT") ) == TRUE ) {
6.287 gchar *new_version = NULL;
6.288 @@ -939,7 +957,7 @@
6.289 gmyth_socket_connect( gmyth_socket, gmyth_socket->hostname, gmyth_socket->port );
6.290 }
6.291
6.292 - if ( gmyth_socket->sd_io_ch->is_readable )
6.293 + if ( gmyth_socket->sd_io_ch->is_readable /*&& ( ( io_cond & G_IO_IN ) != 0 )*/ )
6.294 io_status = g_io_channel_read_chars (gmyth_socket->sd_io_ch, buffer, MYTH_PROTOCOL_FIELD_SIZE, &bytes_read, &error);
6.295 else
6.296 return g_string_new("");
6.297 @@ -953,7 +971,7 @@
6.298 gmyth_debug ( "[%s] Bytes read = %d\n", __FUNCTION__, bytes_read );
6.299
6.300 if( (io_status == G_IO_STATUS_ERROR) || (bytes_read <= 0) ) {
6.301 - g_warning ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__);
6.302 + g_debug ("[%s] Error in mythprotocol response from backend\n", __FUNCTION__);
6.303 str = NULL;
6.304 //return NULL;
6.305 } else {
6.306 @@ -962,7 +980,7 @@
6.307 /* verify if the input (read) buffer is ready to receive data */
6.308 io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
6.309
6.310 - if ( ( io_cond & G_IO_IN ) != 0 ) {
6.311 + //if ( ( io_cond & G_IO_IN ) != 0 ) {
6.312 //gchar *buffer_aux = NULL;
6.313
6.314 /* removes trailing whitespace */
6.315 @@ -992,7 +1010,7 @@
6.316 return g_string_new("");
6.317
6.318 buffer[bytes_read] = '\0';
6.319 - }
6.320 + //}
6.321 }
6.322
6.323 //g_static_mutex_unlock( &mutex );
6.324 @@ -1078,15 +1096,20 @@
6.325 gint i;
6.326
6.327 response = gmyth_socket_receive_response(gmyth_socket);
6.328 - g_static_mutex_lock( &mutex );
6.329 -
6.330 - gmyth_string_list_clear_all (str_list);
6.331 - str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1);
6.332 -
6.333 - for (i=0; i< g_strv_length (str_array); i++) {
6.334 - gmyth_string_list_append_char_array (str_list, str_array[i] );
6.335 + if ( response != NULL && response->str != NULL && response->len > 0 )
6.336 + {
6.337 +
6.338 + g_static_mutex_lock( &mutex );
6.339 +
6.340 + gmyth_string_list_clear_all (str_list);
6.341 + str_array = g_strsplit (response->str, MYTH_SEPARATOR, -1);
6.342 +
6.343 + for (i=0; i< g_strv_length (str_array); i++) {
6.344 + gmyth_string_list_append_char_array (str_list, str_array[i] );
6.345 + }
6.346 + g_static_mutex_unlock( &mutex );
6.347 +
6.348 }
6.349 - g_static_mutex_unlock( &mutex );
6.350
6.351 g_string_free (response, TRUE);
6.352 g_strfreev (str_array);