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