Blame SOURCES/0004-Factor-out-a-function-to-create-watches.patch

536eb0
From 5399d3d5ce420891adfd4beedb023515a28ceab1 Mon Sep 17 00:00:00 2001
536eb0
From: Frediano Ziglio <freddy77@gmail.com>
536eb0
Date: Fri, 16 Sep 2022 20:14:28 +0100
536eb0
Subject: [PATCH 4/8] Factor out a function to create watches
536eb0
536eb0
---
536eb0
 tools/usbredirect.c | 37 ++++++++++++++++++++-----------------
536eb0
 1 file changed, 20 insertions(+), 17 deletions(-)
536eb0
536eb0
diff --git a/tools/usbredirect.c b/tools/usbredirect.c
536eb0
index 89a42a6..6a8b68b 100644
536eb0
--- a/tools/usbredirect.c
536eb0
+++ b/tools/usbredirect.c
536eb0
@@ -414,6 +414,24 @@ end:
536eb0
     return G_SOURCE_REMOVE;
536eb0
 }
536eb0
 
536eb0
+static void
536eb0
+create_watch(redirect *self)
536eb0
+{
536eb0
+    GSocket *socket = g_socket_connection_get_socket(self->connection);
536eb0
+    int socket_fd = g_socket_get_fd(socket);
536eb0
+    GIOChannel *io_channel =
536eb0
+#ifdef G_OS_UNIX
536eb0
+        g_io_channel_unix_new(socket_fd);
536eb0
+#else
536eb0
+        g_io_channel_win32_new_socket(socket_fd);
536eb0
+#endif
536eb0
+
536eb0
+    self->watch_server_id = g_io_add_watch(io_channel,
536eb0
+            G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR,
536eb0
+            connection_handle_io_cb,
536eb0
+            self);
536eb0
+}
536eb0
+
536eb0
 #ifdef G_OS_UNIX
536eb0
 static gboolean
536eb0
 signal_handler(gpointer user_data)
536eb0
@@ -436,12 +454,7 @@ connection_incoming_cb(GSocketService    *service,
536eb0
     /* Add a GSource watch to handle polling for us and handle IO in the callback */
536eb0
     GSocket *connection_socket = g_socket_connection_get_socket(self->connection);
536eb0
     g_socket_set_keepalive(connection_socket, self->keepalive);
536eb0
-    int socket_fd = g_socket_get_fd(connection_socket);
536eb0
-    GIOChannel *io_channel = g_io_channel_unix_new(socket_fd);
536eb0
-    self->watch_server_id = g_io_add_watch(io_channel,
536eb0
-            G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR,
536eb0
-            connection_handle_io_cb,
536eb0
-            self);
536eb0
+    create_watch(self);
536eb0
     return G_SOURCE_REMOVE;
536eb0
 }
536eb0
 
536eb0
@@ -551,17 +564,7 @@ main(int argc, char *argv[])
536eb0
 
536eb0
         GSocket *connection_socket = g_socket_connection_get_socket(self->connection);
536eb0
         g_socket_set_keepalive(connection_socket, self->keepalive);
536eb0
-        int socket_fd = g_socket_get_fd(connection_socket);
536eb0
-        GIOChannel *io_channel =
536eb0
-#ifdef G_OS_UNIX
536eb0
-            g_io_channel_unix_new(socket_fd);
536eb0
-#else
536eb0
-            g_io_channel_win32_new_socket(socket_fd);
536eb0
-#endif
536eb0
-        self->watch_server_id = g_io_add_watch(io_channel,
536eb0
-                G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR,
536eb0
-                connection_handle_io_cb,
536eb0
-                self);
536eb0
+        create_watch(self);
536eb0
     } else {
536eb0
         GSocketService *socket_service;
536eb0
 
536eb0
-- 
536eb0
2.39.0
536eb0