[gtk-vnc] connection: timeout connect() after 10s
- From: Daniel P. Berrange <dberrange src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-vnc] connection: timeout connect() after 10s
- Date: Mon, 20 May 2013 10:50:15 +0000 (UTC)
commit c81e250e6417fbd4361004524f71eee3cadfd4cc
Author: Marc-André Lureau <marcandre lureau gmail com>
Date: Mon May 13 19:36:53 2013 +0200
connection: timeout connect() after 10s
It can take a minute or so before the connect() fails. Add an explicit
shorter timeout of 10s.
https://bugzilla.gnome.org/show_bug.cgi?id=700240
src/vncconnection.c | 50 ++++++++++++++++++++++++++++++++++++--------------
1 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 569f441..46f41f7 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -5026,7 +5026,17 @@ static gboolean vnc_connection_open_fd_internal(VncConnection *conn)
return !vnc_connection_has_error(conn);
}
-static GSocket *vnc_connection_connect_socket(GSocketAddress *sockaddr,
+static gboolean connect_timeout(gpointer data)
+{
+ struct wait_queue *wait = data;
+
+ g_io_wakeup(wait);
+
+ return FALSE;
+}
+
+static GSocket *vnc_connection_connect_socket(struct wait_queue *wait,
+ GSocketAddress *sockaddr,
GError **error)
{
GSocket *sock = g_socket_new(g_socket_address_get_family(sockaddr),
@@ -5037,27 +5047,39 @@ static GSocket *vnc_connection_connect_socket(GSocketAddress *sockaddr,
if (!sock)
return NULL;
+ guint timeout = g_timeout_add_seconds(10, connect_timeout, wait);
+
g_socket_set_blocking(sock, FALSE);
if (!g_socket_connect(sock, sockaddr, NULL, error)) {
if (*error && (*error)->code == G_IO_ERROR_PENDING) {
g_error_free(*error);
*error = NULL;
VNC_DEBUG("Socket pending");
- g_io_wait(sock, G_IO_OUT|G_IO_ERR|G_IO_HUP);
-
- if (!g_socket_check_connect_result(sock, error)) {
- VNC_DEBUG("Failed to connect %s", (*error)->message);
- g_object_unref(sock);
- return NULL;
+ if (!g_io_wait_interruptable(wait, sock, G_IO_OUT|G_IO_ERR|G_IO_HUP)) {
+ VNC_DEBUG("connect interrupted");
+ timeout = 0;
+ goto timeout;
}
- } else {
- VNC_DEBUG("Socket error: %s", *error ? (*error)->message : "unknown");
- g_object_unref(sock);
- return NULL;
- }
+
+ if (!g_socket_check_connect_result(sock, error))
+ goto error;
+ } else
+ goto error;
}
VNC_DEBUG("Finally connected");
+ goto end;
+
+error:
+ VNC_DEBUG("Socket error: %s", *error ? (*error)->message : "unknown");
+
+timeout:
+ g_object_unref(sock);
+ sock = NULL;
+
+end:
+ if (timeout != 0)
+ g_source_remove(timeout);
return sock;
}
@@ -5070,7 +5092,7 @@ static gboolean vnc_connection_open_addr_internal(VncConnection *conn)
VNC_DEBUG("Connecting with addr %p", priv->addr);
- sock = vnc_connection_connect_socket(priv->addr, &conn_error);
+ sock = vnc_connection_connect_socket(&priv->wait, priv->addr, &conn_error);
g_clear_error(&conn_error);
if (sock) {
priv->sock = sock;
@@ -5105,7 +5127,7 @@ static gboolean vnc_connection_open_host_internal(VncConnection *conn)
(sockaddr = g_socket_address_enumerator_next(enumerator, NULL, &conn_error))) {
VNC_DEBUG("Trying one socket");
g_clear_error(&conn_error);
- sock = vnc_connection_connect_socket(sockaddr, &conn_error);
+ sock = vnc_connection_connect_socket(&priv->wait, sockaddr, &conn_error);
g_object_unref(sockaddr);
}
g_object_unref(enumerator);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]