[System] Tweak tests to work with Thread.Interrupt as well.
[mono.git] / mcs / class / System / Test / System.Net / SocketResponder.cs
index daa183afa063a8eda52b943fb8ff8c5a7f4f3f5b..af05477fb6bee65d47eff4747392d2376ce00057 100644 (file)
@@ -131,12 +131,16 @@ namespace MonoTests.System.Net
                                        }
                                } catch (SocketException ex) {
                                        // ignore interruption of blocking call
-                                       if (ex.ErrorCode != SOCKET_CLOSED && ex.ErrorCode != SOCKET_INVALID_ARGS)
+                                       if (ex.ErrorCode != SOCKET_CLOSED && ex.ErrorCode != SOCKET_INVALID_ARGS && _state != STATE_STOPPED)
                                                throw;
                                } catch (ObjectDisposedException ex) {
                                        Console.WriteLine (ex);
                                        if (_state != STATE_STOPPED)
                                                throw;
+#if !MONO_FEATURE_THREAD_ABORT
+                               } catch (ThreadInterruptedException) {
+                                       break;
+#endif
 #if MOBILE
                                } catch (InvalidOperationException ex) {
                                        // This breaks some tests running on Android. The problem is that the stack trace
@@ -146,7 +150,15 @@ namespace MonoTests.System.Net
                                        Console.WriteLine (ex);
 #endif
                                } finally {
+#if MONO_FEATURE_THREAD_ABORT
                                        Thread.Sleep (500);
+#else
+                                       try {
+                                               Thread.Sleep (500);
+                                       } catch (ThreadInterruptedException) {
+                                               // nothing to do
+                                       }
+#endif
                                        if (listenSocket != null)
                                                listenSocket.Close ();
                                }