1.1 --- a/gmyth/src/gmyth_file_transfer.c Wed Dec 06 14:25:19 2006 +0000
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Wed Dec 06 14:32:10 2006 +0000
1.3 @@ -581,7 +581,6 @@
1.4 guint64
1.5 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer)
1.6 {
1.7 - assert (transfer);
1.8 -
1.9 + g_return_val_if_fail (transfer != NULL, 0);
1.10 return transfer->filesize;
1.11 }
2.1 --- a/gmyth/src/gmyth_socket.c Wed Dec 06 14:25:19 2006 +0000
2.2 +++ b/gmyth/src/gmyth_socket.c Wed Dec 06 14:32:10 2006 +0000
2.3 @@ -108,7 +108,7 @@
2.4 * @return gint that represents the error number from getaddrinfo().
2.5 */
2.6 static gint
2.7 -gmyth_socket_toaddrinfo (gchar *addr, gint port, struct addrinfo **addrInfo )
2.8 +gmyth_socket_toaddrinfo (const gchar *addr, gint port, struct addrinfo **addrInfo )
2.9 {
2.10 struct addrinfo *hints;
2.11 gchar *portStr = NULL;
2.12 @@ -467,7 +467,7 @@
2.13
2.14 /* Get the return code from the connect */
2.15 len = sizeof( ret );
2.16 - *err=getsockopt( fd, SOL_SOCKET, SO_ERROR, &ret, &len );
2.17 + *err=getsockopt( fd, SOL_SOCKET, SO_ERROR, &ret, (socklen_t *) &len);
2.18
2.19 if( *err < 0 ) {
2.20 g_warning( "[%s] Connection usnsucessfull.\n", __FUNCTION__ );
2.21 @@ -504,16 +504,20 @@
2.22 if ( hostname == NULL )
2.23 g_printerr ( "[%s] Invalid hostname parameter!\n", __FUNCTION__ );
2.24
2.25 - errno = gmyth_socket_toaddrinfo( hostname, port, &addr_info_data );
2.26 + errno = gmyth_socket_toaddrinfo ( hostname, port, &addr_info_data );
2.27
2.28 g_return_val_if_fail( addr_info_data != NULL, FALSE );
2.29
2.30 /* store hostname and port number */
2.31 + if (gmyth_socket->hostname != NULL) {
2.32 + g_free (gmyth_socket->hostname);
2.33 + gmyth_socket->hostname = NULL;
2.34 + }
2.35 +
2.36 gmyth_socket->hostname = g_strdup( hostname );
2.37 gmyth_socket->port = port;
2.38
2.39 for ( addr_info0 = addr_info_data; addr_info0; addr_info0 = addr_info_data->ai_next ) {
2.40 - struct sockaddr_in *sa = (struct sockaddr_in*)addr_info0->ai_addr;
2.41 /* init socket descriptor */
2.42 gmyth_socket->sd = socket( addr_info0->ai_family, addr_info0->ai_socktype,
2.43 addr_info0->ai_protocol );
2.44 @@ -521,25 +525,22 @@
2.45 if ( gmyth_socket->sd < 0 )
2.46 continue;
2.47
2.48 - gmyth_debug( "[%s] hostname = %s, sock_fd = %d, addr = %s, addr_len = %d, "\
2.49 - "ai_family = %d, ai_protocol = %d\n",
2.50 - __FUNCTION__, hostname, gmyth_socket->sd, inet_ntoa( sa->sin_addr ),
2.51 - addr_info0->ai_addrlen, addr_info0->ai_family, addr_info0->ai_protocol );
2.52 -
2.53 - struct timeval *timeout = g_new0( struct timeval, 1 );
2.54 + struct timeval timeout;
2.55
2.56 /* using 40 seconds timeout */
2.57 - timeout->tv_sec = 40;
2.58 - timeout->tv_usec = 0;
2.59 + timeout.tv_sec = 40;
2.60 + timeout.tv_usec = 0;
2.61
2.62 - if ( gmyth_socket_try_connect( gmyth_socket->sd, (struct sockaddr *)addr_info0->ai_addr,
2.63 - addr_info0->ai_addrlen, timeout, &ret_code ) < 0 )
2.64 + if (gmyth_socket_try_connect (gmyth_socket->sd, (struct sockaddr *)addr_info0->ai_addr,
2.65 + addr_info0->ai_addrlen, &timeout, &ret_code ) < 0 )
2.66 {
2.67 g_printerr( "[%s] Error connecting to backend!\n", __FUNCTION__ );
2.68 - if ( ret_code == ETIMEDOUT )
2.69 - g_printerr( "[%s]\tBackend host unreachable!\n", __FUNCTION__ );
2.70 + if (ret_code == ETIMEDOUT)
2.71 + g_printerr( "[%s]\tBackend host unreachable!\n", __FUNCTION__ );
2.72
2.73 - g_printerr( "ERROR: %s\n", gai_strerror(ret_code) );
2.74 + close (gmyth_socket->sd);
2.75 + gmyth_socket->sd = -1;
2.76 + g_printerr ("ERROR: %s\n", gai_strerror(ret_code));
2.77 continue;
2.78 }
2.79
2.80 @@ -549,7 +550,12 @@
2.81 freeaddrinfo (addr_info_data);
2.82 addr_info_data = NULL;
2.83
2.84 - gmyth_socket->sd_io_ch = g_io_channel_unix_new( gmyth_socket->sd );
2.85 + if (gmyth_socket->sd_io_ch != NULL) {
2.86 + g_io_channel_unref (gmyth_socket->sd_io_ch);
2.87 + gmyth_socket->sd_io_ch = NULL;
2.88 + }
2.89 +
2.90 + gmyth_socket->sd_io_ch = g_io_channel_unix_new (gmyth_socket->sd);
2.91
2.92 //GIOFlags flags = g_io_channel_get_flags (gmyth_socket->sd_io_ch);
2.93 /* unset the nonblock flag */
2.94 @@ -559,9 +565,7 @@
2.95 //g_io_channel_set_flags (gmyth_socket->sd_io_ch, flags, NULL);
2.96
2.97 ret = ( ret_code == 0 ) ? TRUE : FALSE ;
2.98 -
2.99 return ret;
2.100 -
2.101 }
2.102
2.103 /** Gets the GIOChannel associated to the given GMythSocket.
2.104 @@ -633,6 +637,8 @@
2.105 GIOStatus io_status = G_IO_STATUS_NORMAL;
2.106 //GIOCondition io_cond;
2.107 GError* error = NULL;
2.108 +
2.109 +
2.110 gchar *buffer = NULL;
2.111
2.112 gsize bytes_written = 0;
2.113 @@ -796,6 +802,12 @@
2.114 gmyth_socket_close_connection (GMythSocket *gmyth_socket)
2.115 {
2.116 close (gmyth_socket->sd);
2.117 + gmyth_socket->sd = -1;
2.118 +
2.119 + if (gmyth_socket->sd_io_ch != NULL) {
2.120 + g_io_channel_unref (gmyth_socket->sd_io_ch);
2.121 + gmyth_socket->sd_io_ch = NULL;
2.122 + }
2.123 }
2.124
2.125