X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fsocket.c;h=662224e5dc1ceed1d72fe1c3d73663d22bc15799;hb=f502ad7eec6117b80c415b0c6ed45989afab5aaa;hp=cfb3b7d1f85194edac1818c37fad5ed7ff5e5461;hpb=dd5a1c908b00ef199fc3ac8268ac1fd7ab194e33;p=catta diff --git a/src/socket.c b/src/socket.c index cfb3b7d..662224e 100644 --- a/src/socket.c +++ b/src/socket.c @@ -191,6 +191,16 @@ static int bind_with_warn(int fd, const struct sockaddr *sa, socklen_t l) { assert(sa); assert(l > 0); +#ifdef _WIN32 + // Windows does not allow address reuse when SO_REUSEADDR was set after + // bind() on the first socket, so we must set it before. + // Note that this spoils the detection trickery below and the warning will + // not be logged. + + if (reuseaddr(fd) < 0) + return -1; +#endif + if (bind(fd, sa, l) < 0) { if (errno != EADDRINUSE) { @@ -452,7 +462,7 @@ static int sendmsg_loop(int fd, struct msghdr *msg, int flags) { if (errno == EINTR) continue; - if (errno != EAGAIN) { + if (errno != EAGAIN && errno != EWOULDBLOCK) { char where[64]; struct sockaddr_in *sin = msg->msg_name;