From b0398adc12cb62d0690423ac628e279dbd6c5e18 Mon Sep 17 00:00:00 2001 From: Christian Ulrich Date: Sat, 24 Oct 2020 19:00:49 +0200 Subject: [PATCH] use SO_REUSEADDR in accept loop --- examples/app/app.nim | 2 +- punchd.nim | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/app/app.nim b/examples/app/app.nim index ca22888..642655e 100644 --- a/examples/app/app.nim +++ b/examples/app/app.nim @@ -239,7 +239,7 @@ proc runApp(serverHostname: string, serverPort: Port, peerId: string, srcPort) asyncCheck handleServerMessages(serverConn) let sock = await punchHole(punchdConn, serverConn, peerId, otherPeerId, - "tcp-nutss") + "tcp-syni") echo "connected!" await sock.send("ping") let msg = await sock.recv(4) diff --git a/punchd.nim b/punchd.nim index a3578e7..5125ee7 100644 --- a/punchd.nim +++ b/punchd.nim @@ -48,6 +48,7 @@ proc acceptConnections(punchd: Punchd, ip: IpAddress, port: Port, else: assert(false, "can only accept TCP or UDP connections") let sock = newAsyncSocket(sockType = sockType, protocol = protocol) + sock.setSockOpt(OptReuseAddr, true) sock.bindAddr(port, $ip) sock.listen() while true: