]> git.meshlink.io Git - catta/blobdiff - src/socket.c
check for both EAGAIN and EWOULDBLOCK from sendmsg
[catta] / src / socket.c
index cfb3b7d1f85194edac1818c37fad5ed7ff5e5461..662224e5dc1ceed1d72fe1c3d73663d22bc15799 100644 (file)
@@ -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;