1.1 --- a/gmyth/src/gmyth_socket.c Wed Jan 10 21:47:24 2007 +0000
1.2 +++ b/gmyth/src/gmyth_socket.c Wed Jan 10 22:31:34 2007 +0000
1.3 @@ -472,6 +472,7 @@
1.4 FD_ZERO( &fd_w );
1.5 FD_SET( fd, &fd_w );
1.6
1.7 + printf ("xxxxxxxxxxxx %d\n", timeout->tv_sec);
1.8 *err = select( FD_SETSIZE, NULL, &fd_w, NULL, timeout);
1.9 if ( *err < 0 ) {
1.10 g_warning( "[%s] Connection unsucessfull (timed out).\n", __FUNCTION__ );
1.11 @@ -513,10 +514,20 @@
1.12 * @param port The backend port.
1.13 * @return TRUE if success, FALSE if error.
1.14 */
1.15 +
1.16 +
1.17 gboolean
1.18 gmyth_socket_connect (GMythSocket *gmyth_socket,
1.19 const gchar *hostname, gint port)
1.20 {
1.21 + return gmyth_socket_connect_with_timeout (gmyth_socket,
1.22 + hostname, port, 0);
1.23 +}
1.24 +
1.25 +gboolean
1.26 +gmyth_socket_connect_with_timeout (GMythSocket *gmyth_socket,
1.27 + const gchar *hostname, gint port, guint timeout)
1.28 +{
1.29 struct addrinfo *addr_info_data = NULL, *addr_info0 = NULL;
1.30 gint ret_code = -1;
1.31 gint errno;
1.32 @@ -548,14 +559,17 @@
1.33 if ( gmyth_socket->sd < 0 )
1.34 continue;
1.35
1.36 - struct timeval timeout;
1.37 + struct timeval *timeout_val = NULL;
1.38 + if (timeout != 0) {
1.39 + timeout_val = g_new0 (struct timeval, 1);
1.40 +
1.41 + timeout_val->tv_sec = timeout;
1.42 + printf ("XXXXXXXXXXX setting timeout %d\n", timeout_val->tv_sec);
1.43 + timeout_val->tv_usec = 0;
1.44 + }
1.45
1.46 - /* using 40 seconds timeout */
1.47 - timeout.tv_sec = 40;
1.48 - timeout.tv_usec = 0;
1.49 -
1.50 if (gmyth_socket_try_connect (gmyth_socket->sd, (struct sockaddr *)addr_info0->ai_addr,
1.51 - addr_info0->ai_addrlen, &timeout, &ret_code ) < 0 )
1.52 + addr_info0->ai_addrlen, timeout_val, &ret_code ) < 0 )
1.53 {
1.54 g_printerr( "[%s] Error connecting to backend!\n", __FUNCTION__ );
1.55 if (ret_code == ETIMEDOUT)
1.56 @@ -564,12 +578,16 @@
1.57 close (gmyth_socket->sd);
1.58 gmyth_socket->sd = -1;
1.59 g_printerr ("ERROR: %s\n", gai_strerror(ret_code));
1.60 + g_free (timeout_val);
1.61 continue;
1.62 }
1.63
1.64 + g_free (timeout_val);
1.65 +
1.66 /* only will be reached if none of the error above occurred */
1.67 break;
1.68 }
1.69 +
1.70 freeaddrinfo (addr_info_data);
1.71 addr_info_data = NULL;
1.72
2.1 --- a/gmyth/src/gmyth_socket.h Wed Jan 10 21:47:24 2007 +0000
2.2 +++ b/gmyth/src/gmyth_socket.h Wed Jan 10 22:31:34 2007 +0000
2.3 @@ -97,6 +97,9 @@
2.4
2.5 gboolean gmyth_socket_connect (GMythSocket *gmyth_socket,
2.6 const gchar *hostname, gint port);
2.7 +gboolean gmyth_socket_connect_with_timeout (GMythSocket *gmyth_socket,
2.8 + const gchar *hostname, gint port, guint timeout);
2.9 +
2.10 gboolean gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket,
2.11 const gchar *hostname_backend, gint port,
2.12 gboolean blocking_client);
3.1 --- a/gmyth/tests/gmyth_test_connection.c Wed Jan 10 21:47:24 2007 +0000
3.2 +++ b/gmyth/tests/gmyth_test_connection.c Wed Jan 10 22:31:34 2007 +0000
3.3 @@ -9,9 +9,9 @@
3.4 test_backend_connection1 (GMythBackendInfo *backend_info)
3.5 {
3.6 GMythSocket *socket = gmyth_socket_new ();
3.7 - if (gmyth_socket_connect (socket,
3.8 + if (gmyth_socket_connect_with_timeout (socket,
3.9 gmyth_backend_info_get_hostname (backend_info),
3.10 - gmyth_backend_info_get_port (backend_info)) == TRUE) {
3.11 + gmyth_backend_info_get_port (backend_info), 4) == TRUE) {
3.12 g_debug ("Connection success");
3.13 return TRUE;
3.14 } else {
3.15 @@ -47,8 +47,8 @@
3.16
3.17 backend_info = gmyth_backend_info_new_with_uri (argv[1]);
3.18
3.19 + test_backend_connection1 (backend_info);
3.20 test_mysql_connection1 (backend_info);
3.21 - test_backend_connection1 (backend_info);
3.22 }
3.23
3.24