Files
mono/mcs/class/System/Test/System.Net.Sockets/AbortBlockingSocketCallTest.cs
Johan Lorensson 80e5e7ff62 Cancel sync IO on Windows when aborting thread. (#13173)
* Cancel sync IO on Windows when aborting thread.

Using CancelIO/CancelIOEx or CancelSynchronousIo on a thread that is moving
into a suspended state can cause these calls to hang (they shouldn’t but
have been observed to be the case). Fix does the cancel of sync IO after
the aborted thread has been resumed, but before releasing suspend locks
making sure thread won't be suspend again until after cancel IO call has
completed.

* Add tests aborting blocking socket and file IO on Windows.
2019-02-28 16:02:21 -05:00

46 lines
790 B
C#

using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using NUnit.Framework;
using System.IO;
using MonoTests.Helpers;
namespace MonoTests.System.Net.Sockets
{
[TestFixture]
public class AbortBlockingSocketCallTest
{
void StartBlockingAcceptCall ()
{
TcpListener listener = null;
try
{
listener = NetworkHelpers.CreateAndStartTcpListener (out int port);
Socket socket = listener.AcceptSocket ();
socket.Close ();
}
finally
{
if (listener != null)
listener.Stop ();
}
}
[Test]
public void AbortBlockingAcceptCall ()
{
Thread listenerThread = new Thread (StartBlockingAcceptCall);
listenerThread.Start ();
Thread.Sleep (2000);
listenerThread.Abort ();
listenerThread.Join ();
}
}
}