Skip to content
Browse files

Add new cancel_blocking_socket_operation icall to Socket.

	* socket-io.c: Add cancel_blocking_socket_operation icall
	to Socket so we can abort socket syscalls on other threads
	when we decide to close a socket.
  • Loading branch information...
1 parent 794227d commit 150d98b95e6b1c44677a19110315ef08b40fe95e @kumpera kumpera committed
Showing with 17 additions and 0 deletions.
  1. +1 −0 mono/metadata/icall-def.h
  2. +15 −0 mono/metadata/socket-io.c
  3. +1 −0 mono/metadata/socket-io.h
View
1 mono/metadata/icall-def.h
@@ -466,6 +466,7 @@ ICALL(SOCK_18, "SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionL
ICALL(SOCK_19, "Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal)
ICALL(SOCK_20, "Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal)
ICALL(SOCK_21, "WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl)
+ICALL(SOCK_21a, "cancel_blocking_socket_operation", icall_cancel_blocking_socket_operation)
ICALL(SOCK_22, "socket_pool_queue", icall_append_io_job)
ICALL_TYPE(SOCKEX, "System.Net.Sockets.SocketException", SOCKEX_1)
View
15 mono/metadata/socket-io.c
@@ -49,6 +49,7 @@
#include <mono/metadata/class-internals.h>
#include <mono/metadata/threadpool-internals.h>
#include <mono/metadata/domain-internals.h>
+#include <mono/utils/mono-threads.h>
#include <time.h>
#ifdef HAVE_SYS_TIME_H
@@ -3266,5 +3267,19 @@ void mono_network_cleanup(void)
WSACleanup();
}
+void
+icall_cancel_blocking_socket_operation (MonoThread *thread)
+{
+ MonoInternalThread *internal = thread->internal_thread;
+
+ if (mono_thread_info_new_interrupt_enabled ()) {
+ mono_thread_info_abort_socket_syscall_for_close ((MonoNativeThreadId)(gsize)internal->tid);
+ } else {
+#ifndef HOST_WIN32
+ internal->ignore_next_signal = TRUE;
+ mono_thread_kill (internal, mono_thread_get_abort_signal ());
+#endif
+ }
+}
#endif /* #ifndef DISABLE_SOCKETS */
View
1 mono/metadata/socket-io.h
@@ -220,6 +220,7 @@ extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_
extern MonoBoolean ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 *error) MONO_INTERNAL;
extern void ves_icall_System_Net_Sockets_Socket_Disconnect_internal(SOCKET sock, MonoBoolean reuse, gint32 *error) MONO_INTERNAL;
extern gboolean ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags) MONO_INTERNAL;
+void icall_cancel_blocking_socket_operation (MonoThread *thread) MONO_INTERNAL;
extern void mono_network_init(void) MONO_INTERNAL;
extern void mono_network_cleanup(void) MONO_INTERNAL;

0 comments on commit 150d98b

Please sign in to comment.
Something went wrong with that request. Please try again.