[socket] Ensure werror is initialized to 0
[mono.git] / mono / metadata / w32socket.c
index 9d45ddac9215782b7a090e9f2fc785ba1ade4271..57e8d4c2635f35b4ada7172f32074109044ee7cd 100644 (file)
 #include <sys/types.h>
 
 #include <mono/metadata/object.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/appdomain.h>
-#include <mono/metadata/file-io.h>
+#include <mono/metadata/w32file.h>
 #include <mono/metadata/threads.h>
 #include <mono/metadata/threads-types.h>
 #include <mono/metadata/threadpool-io.h>
@@ -64,6 +63,7 @@
 #include <mono/metadata/w32handle.h>
 #include <mono/metadata/w32socket.h>
 #include <mono/metadata/w32socket-internals.h>
+#include <mono/metadata/w32error.h>
 
 #include <time.h>
 #ifdef HAVE_SYS_TIME_H
@@ -157,6 +157,12 @@ mono_w32socket_ioctl (SOCKET sock, gint32 command, gchar *input, gint inputlen,
        return WSAIoctl (sock, command, input, inputlen, output, outputlen, written, NULL, NULL);
 }
 
+static gboolean
+mono_w32socket_close (SOCKET sock)
+{
+       return CloseHandle (sock);
+}
+
 #endif /* HOST_WIN32 */
 
 static void
@@ -702,7 +708,7 @@ ves_icall_System_Net_Sockets_Socket_Close_internal (gsize sock, gint32 *werror)
        mono_threadpool_io_remove_socket (GPOINTER_TO_INT (sock));
 
        MONO_ENTER_GC_SAFE;
-       CloseHandle (GINT_TO_POINTER (sock));
+       mono_w32socket_close ((SOCKET) sock);
        MONO_EXIT_GC_SAFE;
 }
 
@@ -2632,15 +2638,16 @@ ves_icall_System_Net_Sockets_Socket_SendFile_internal (gsize sock, MonoString *f
        gboolean interrupted;
        TRANSMIT_FILE_BUFFERS buffers;
 
+       *werror = 0;
+
        if (filename == NULL)
                return FALSE;
 
        /* FIXME: replace file by a proper fd that we can call open and close on, as they are interruptible */
 
-       file = ves_icall_System_IO_MonoIO_Open (filename, FileMode_Open, FileAccess_Read, FileShare_Read, 0, werror);
-
+       file = mono_w32file_create (mono_string_chars (filename), OPEN_EXISTING, GENERIC_READ, FILE_SHARE_READ, 0);
        if (file == INVALID_HANDLE_VALUE) {
-               SetLastError (*werror);
+               *werror = mono_w32error_get_last ();
                return FALSE;
        }
 
@@ -2656,8 +2663,8 @@ ves_icall_System_Net_Sockets_Socket_SendFile_internal (gsize sock, MonoString *f
 
        mono_thread_info_install_interrupt (abort_syscall, (gpointer) (gsize) mono_native_thread_id_get (), &interrupted);
        if (interrupted) {
-               CloseHandle (file);
-               SetLastError (WSAEINTR);
+               mono_w32file_close (file);
+               mono_w32error_set_last (WSAEINTR);
                return FALSE;
        }
 
@@ -2670,14 +2677,14 @@ ves_icall_System_Net_Sockets_Socket_SendFile_internal (gsize sock, MonoString *f
 
        mono_thread_info_uninstall_interrupt (&interrupted);
        if (interrupted) {
-               CloseHandle (file);
+               mono_w32file_close (file);
                *werror = WSAEINTR;
                return FALSE;
        }
 
        MONO_ENTER_GC_SAFE;
 
-       CloseHandle (file);
+       mono_w32file_close (file);
 
        MONO_EXIT_GC_SAFE;