summaryrefslogtreecommitdiff
path: root/tools/usbredirect.c
diff options
context:
space:
mode:
authorVictor Toso <victortoso@redhat.com>2021-02-10 10:05:21 +0100
committerVictor Toso <victortoso@redhat.com>2021-03-04 10:59:20 +0100
commit12f1f0a76e51a5ad2d4c11245997b5502adc0d3a (patch)
treeb872ab2415075cf1ffb12f926b017352540a91c0 /tools/usbredirect.c
parentcbd69b99059a75914129f645013b1e6fa043c305 (diff)
usbredirect: Add keepalive flag
In order to make feature parity with usbredirserver, enabling/disabling SO_KEEPALIVE is necessary. GIO does not have an API to change default value (which depends on protocol, etc). If this seems necessary in the future, we either add that to GIO or retrieve the fd and do set it ourselves. Signed-off-by: Victor Toso <victortoso@redhat.com>
Diffstat (limited to 'tools/usbredirect.c')
-rw-r--r--tools/usbredirect.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/usbredirect.c b/tools/usbredirect.c
index ce87783..2882165 100644
--- a/tools/usbredirect.c
+++ b/tools/usbredirect.c
@@ -24,6 +24,7 @@ struct redirect {
int product;
} device;
bool is_client;
+ bool keepalive;
char *addr;
int port;
@@ -88,12 +89,14 @@ parse_opts(int *argc, char ***argv)
char *device = NULL;
char *remoteaddr = NULL;
char *localaddr = NULL;
+ gboolean keepalive = FALSE;
struct redirect *self = NULL;
GOptionEntry entries[] = {
{ "device", 0, 0, G_OPTION_ARG_STRING, &device, "Local USB device to be redirected", NULL },
{ "to", 0, 0, G_OPTION_ARG_STRING, &remoteaddr, "Client URI to connect to", NULL },
{ "as", 0, 0, G_OPTION_ARG_STRING, &localaddr, "Server URI to be run", NULL },
+ { "keepalive", 'k', 0, G_OPTION_ARG_NONE, &keepalive, "If we should set SO_KEEPALIVE flag on underlying socket", NULL },
{ NULL }
};
@@ -130,6 +133,10 @@ parse_opts(int *argc, char ***argv)
goto end;
}
+ self->keepalive = keepalive;
+ g_debug("options: keepalive=%s",
+ self->keepalive ? "ON":"OFF");
+
end:
if (self) {
g_debug("Device: '%04x:%04x', %s addr: '%s', port: %d\n",
@@ -332,6 +339,7 @@ connection_incoming_cb(GSocketService *service,
/* Add a GSource watch to handle polling for us and handle IO in the callback */
GSocket *connection_socket = g_socket_connection_get_socket(self->connection);
+ g_socket_set_keepalive(connection_socket, self->keepalive);
int socket_fd = g_socket_get_fd(connection_socket);
GIOChannel *io_channel = g_io_channel_unix_new(socket_fd);
self->watch_server_id = g_io_add_watch(io_channel,
@@ -429,6 +437,7 @@ main(int argc, char *argv[])
}
GSocket *connection_socket = g_socket_connection_get_socket(self->connection);
+ g_socket_set_keepalive(connection_socket, self->keepalive);
int socket_fd = g_socket_get_fd(connection_socket);
GIOChannel *io_channel =
#ifdef G_OS_UNIX