diff --git a/Changelog b/Changelog index d31324f..bb4831f 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,6 @@ 2019-02-03: - fixed: if connection could not established we need to clear sock to -1 +- fixed: setsockopt SO_REUSE was not right option was not setup properly 2019-01-30: - Adding unix socket to the possible connections diff --git a/tcp.cc b/tcp.cc index 66e500d..1548564 100644 --- a/tcp.cc +++ b/tcp.cc @@ -63,9 +63,11 @@ int TCP::Listen(int port) { sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (sock == -1) continue; + i = 1; if ((err = setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i))) != 0) { printf ("%s:%d setsockopt error\n", __FILE__, __LINE__); } + if ((err = bind (sock, rp->ai_addr, rp->ai_addrlen)) < 0) { close (sock); sock = -1;