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.
This commit is contained in:
parent
6db22ef339
commit
60f3185185
1 changed files with 5 additions and 0 deletions
|
@ -25,6 +25,11 @@ socket_t net_listen(Uint32 addr, Uint16 port, int backlog) {
|
||||||
return INVALID_SOCKET;
|
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;
|
SOCKADDR_IN sin;
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
sin.sin_addr.s_addr = htonl(addr); // htonl() harmless on INADDR_ANY
|
sin.sin_addr.s_addr = htonl(addr); // htonl() harmless on INADDR_ANY
|
||||||
|
|
Loading…
Reference in a new issue