Revert "[w32handle] Remove use of w32handle for File, Console, Pipe and Socket (...
[mono.git] / mono / metadata / w32socket-unix.c
index c10b210036825595d708b2b77a814abe1b855c84..5816b142b051e09e6c784e93518bbd9241dbd643 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * w32socket-unix.c: Unix specific socket code.
+/**
+ * \file
+ * Unix specific socket code.
  *
  * Copyright 2016 Microsoft
  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
@@ -11,6 +12,7 @@
 #include <pthread.h>
 #include <string.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <sys/socket.h>
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
@@ -26,7 +28,6 @@
 #endif
 #include <errno.h>
 #include <fcntl.h>
-#include <sys/types.h>
 #ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
 #endif
@@ -1134,6 +1135,7 @@ mono_w32socket_close (SOCKET sock)
 gint
 mono_w32socket_set_blocking (SOCKET socket, gboolean blocking)
 {
+#ifdef O_NONBLOCK
        gint ret;
        gpointer handle;
 
@@ -1143,14 +1145,12 @@ mono_w32socket_set_blocking (SOCKET socket, gboolean blocking)
                return SOCKET_ERROR;
        }
 
-#ifdef O_NONBLOCK
        /* This works better than ioctl(...FIONBIO...)
         * on Linux (it causes connect to return
         * EINPROGRESS, but the ioctl doesn't seem to) */
        ret = fcntl (socket, F_GETFL, 0);
        if (ret != -1)
                ret = fcntl (socket, F_SETFL, blocking ? (ret & (~O_NONBLOCK)) : (ret | (O_NONBLOCK)));
-#endif /* O_NONBLOCK */
 
        if (ret == -1) {
                gint errnum = errno;
@@ -1160,6 +1160,10 @@ mono_w32socket_set_blocking (SOCKET socket, gboolean blocking)
        }
 
        return 0;
+#else
+       mono_w32socket_set_last_error (ERROR_NOT_SUPPORTED);
+       return SOCKET_ERROR;
+#endif /* O_NONBLOCK */
 }
 
 gint
@@ -1320,6 +1324,9 @@ mono_w32socket_convert_error (gint error)
        case ENODEV: return WSAENETDOWN;
 #ifdef EPROTOTYPE
        case EPROTOTYPE: return WSAEPROTOTYPE;
+#endif
+#ifdef ENXIO
+       case ENXIO: return WSAENXIO;
 #endif
        default:
                g_error ("%s: no translation into winsock error for (%d) \"%s\"", __func__, error, g_strerror (error));
@@ -1327,8 +1334,9 @@ mono_w32socket_convert_error (gint error)
 }
 
 gboolean
-ves_icall_System_Net_Sockets_Socket_SupportPortReuse (MonoProtocolType proto)
+ves_icall_System_Net_Sockets_Socket_SupportPortReuse (MonoProtocolType proto, MonoError *error)
 {
+       error_init (error);
 #if defined (SO_REUSEPORT)
        return TRUE;
 #else