Fix exception caused by destroying sockets on Server shutdown
authorkwolekr <kwolekr@minetest.net>
Wed, 25 Dec 2013 04:50:49 +0000 (23:50 -0500)
committerkwolekr <kwolekr@minetest.net>
Tue, 31 Dec 2013 20:00:49 +0000 (15:00 -0500)
src/socket.cpp

index c3873dab65131ab314cc2a4f8b5666b653c36263..78ff364e50cc427b8cf640a43925731daf3a34e0 100644 (file)
@@ -546,7 +546,10 @@ bool UDPSocket::WaitData(int timeout_ms)
 
        if(result == 0)
                return false;
-       else if(result < 0 && errno == EINTR)
+       else if(result < 0 && (errno == EINTR || errno == EBADF))
+               // N.B. select() fails when sockets are destroyed on Connection's dtor
+               // with EBADF.  Instead of doing tricky synchronization, allow this
+               // thread to exit but don't throw an exception.
                return false;
        else if(result < 0)
        {
@@ -557,9 +560,9 @@ bool UDPSocket::WaitData(int timeout_ms)
                int e = WSAGetLastError();
                dstream << (int) m_handle << ": WSAGetLastError()="
                        << e << std::endl;
-               if(e == 10004 /* = WSAEINTR */)
+               if(e == 10004 /* = WSAEINTR */ || e == 10009 /*WSAEBADF*/)
                {
-                       dstream << "WARNING: Ignoring WSAEINTR." << std::endl;
+                       dstream << "WARNING: Ignoring WSAEINTR/WSAEBADF." << std::endl;
                        return false;
                }
 #endif