diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-23 20:11:30 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-23 20:11:30 +0200 |
commit | c59700d8e2f2133acc94d71b33e93ed736bac590 (patch) | |
tree | a4a113150dc2b68c44a970664e43fa439e736ce6 | |
parent | c7147f5ccc6d0fa4a019c54166085a36f86a1bf0 (diff) |
Moved connection code to server_connect().
-rw-r--r-- | server_communication.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/server_communication.c b/server_communication.c index 227eb8f..f2f5946 100644 --- a/server_communication.c +++ b/server_communication.c @@ -2,7 +2,7 @@ #include <gio/gio.h> -gboolean server_sync(struct server *server) { +static GSocket *server_connect(struct server *server) { GError *error = NULL, *conn_error = NULL; GSocketConnectable *addr; GSocketAddressEnumerator *enumerator; @@ -30,19 +30,29 @@ gboolean server_sync(struct server *server) { g_warning("server_sync: no connectable addresses found for host %s", server->host); } - return FALSE; + return NULL; } if(conn == NULL) { g_warning(conn_error->message); g_error_free(conn_error); - return FALSE; + return NULL; } GSocket *socket = g_socket_connection_get_socket(conn); g_debug("connected"); + return socket; +} + +gboolean server_sync(struct server *server) { + GSocket *socket = server_connect(server); + + if(socket == NULL) { + return FALSE; + } + g_socket_send(socket, "ping\n", 5, NULL, NULL); gchar buffer[0x400]; g_socket_receive(socket, buffer, 0x400, NULL, NULL); |