From 60f31851851f0d2297c4bd46140c60554b38b497 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 16 Feb 2018 15:05:43 +0100 Subject: [PATCH] Reuse server address Set SO_REUSEADDR flag to server socket, so that bind() does not fail if we restart scrcpy immediately after we closed the previous one. --- app/src/net.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/net.c b/app/src/net.c index c370dbe3..60fb3988 100644 --- a/app/src/net.c +++ b/app/src/net.c @@ -25,6 +25,11 @@ socket_t net_listen(Uint32 addr, Uint16 port, int backlog) { return INVALID_SOCKET; } + int reuse = 1; + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(reuse)) == -1) { + perror("setsockopt(SO_REUSEADDR)"); + } + SOCKADDR_IN sin; sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(addr); // htonl() harmless on INADDR_ANY