[Socket] Duplicate logic of AsyncResult.ExecuteWorkItem to SocketAsyncResult
authorLudovic Henry <ludovic@xamarin.com>
Thu, 10 Sep 2015 10:32:01 +0000 (11:32 +0100)
committerLudovic Henry <ludovic@xamarin.com>
Thu, 10 Sep 2015 15:59:01 +0000 (16:59 +0100)
This consists in executing the callback synchronously and swallowing any exception in this callback.

mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs
mcs/class/corlib/System/AppDomain.cs
mono/metadata/appdomain.c
mono/metadata/domain-internals.h
mono/metadata/icall-def.h

index f1cd229d865c13fa15a81e734373d105dad93438..f0c4fa22b7b19ef1eab716baf3ac8563e6da320f 100644 (file)
@@ -307,7 +307,11 @@ namespace System.Net.Sockets
                        async_result.Invoke ();
 
                        if (completed && callback != null) {
-                               ThreadPool.UnsafeQueueCustomWorkItem (new AsyncResult (state => callback ((IAsyncResult) state), this, false), false);
+                               try {
+                                       callback (this);
+                               } catch (Exception e) {
+                                       AppDomain.CurrentDomain.DoUnhandledException (e);
+                               }
                        }
                }
 
index 569fc383bfff53e366aaef7f89f43a1d0e3bedfb..22927ecd2f5d668eb44da7da7a933fb180d3983f 100644 (file)
@@ -1345,6 +1345,9 @@ namespace System {
                                DomainUnload(this, null);
                }
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal extern void DoUnhandledException (Exception e);
+
                internal void DoUnhandledException (UnhandledExceptionEventArgs args) {
                        if (UnhandledException != null)
                                UnhandledException (this, args);
index 8e20076bce7130ab0349584dcb09fd500c955c55..8b5816090650388dc2656c734b4faa0becd51a34 100644 (file)
@@ -2032,6 +2032,12 @@ ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id)
        return mono_domain_is_unloading (domain);
 }
 
+void
+ves_icall_System_AppDomain_DoUnhandledException (MonoException *exc)
+{
+       mono_unhandled_exception ((MonoObject*) exc);
+}
+
 gint32
 ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad, 
                                                                                        MonoReflectionAssembly *refass, MonoArray *args)
index 873770b436abd3d9b4807b24ce46aca308403fc8..b58b891c002042dd657ce5832395b82d7ba062c6 100644 (file)
@@ -590,6 +590,9 @@ ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id);
 void
 ves_icall_System_AppDomain_InternalUnload          (gint32 domain_id);
 
+void
+ves_icall_System_AppDomain_DoUnhandledException (MonoException *exc);
+
 gint32
 ves_icall_System_AppDomain_ExecuteAssembly         (MonoAppDomain *ad, 
                                                                                                        MonoReflectionAssembly *refass,
index c6cb943c30cef7ebfd8851d4c9fd761a12f601bf..faca20862bf7b847bef7019d03b3e5fd8d8aa554 100644 (file)
@@ -57,7 +57,8 @@ ICALL(KPAIR_4, "_ProtectMachine", ves_icall_Mono_Security_Cryptography_KeyPairPe
 ICALL(KPAIR_5, "_ProtectUser", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_ProtectUser)
 #endif /* !PLATFORM_RO_FS */
 
-ICALL_TYPE(APPDOM, "System.AppDomain", APPDOM_1)
+ICALL_TYPE(APPDOM, "System.AppDomain", APPDOM_23)
+ICALL(APPDOM_23, "DoUnhandledException", ves_icall_System_AppDomain_DoUnhandledException)
 ICALL(APPDOM_1, "ExecuteAssembly", ves_icall_System_AppDomain_ExecuteAssembly)
 ICALL(APPDOM_2, "GetAssemblies", ves_icall_System_AppDomain_GetAssemblies)
 ICALL(APPDOM_3, "GetData", ves_icall_System_AppDomain_GetData)