summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server_communication.c16
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);