{
private bool islistening;
private bool useoverlappedIO;
+ private const int SOCKET_CLOSED = 10004;
static void AddSockets (List<Socket> sockets, IList list, string name)
{
int error = 0;
IntPtr sock = (IntPtr) (-1);
- blocking_thread = Thread.CurrentThread;
try {
+ blocking_thread = Thread.CurrentThread;
sock = Accept_internal(socket, out error, blocking);
- } catch (ThreadAbortException) {
- if (disposed) {
- Thread.ResetAbort ();
- error = (int) SocketError.Interrupted;
- }
} finally {
blocking_thread = null;
}
- if (error != 0)
- throw new SocketException (error);
-
+ if (error != 0) {
+ if (closed)
+ error = SOCKET_CLOSED;
+ throw new SocketException(error);
+ }
+
Socket accepted = new Socket(this.AddressFamily, this.SocketType,
this.ProtocolType, sock);
int error = 0;
IntPtr sock = (IntPtr)(-1);
- blocking_thread = Thread.CurrentThread;
try {
+ blocking_thread = Thread.CurrentThread;
sock = Accept_internal (socket, out error, blocking);
- } catch (ThreadAbortException) {
- if (disposed) {
- Thread.ResetAbort ();
- error = (int)SocketError.Interrupted;
- }
} finally {
blocking_thread = null;
}
- if (error != 0)
+ if (error != 0) {
+ if (closed)
+ error = SOCKET_CLOSED;
throw new SocketException (error);
+ }
acceptSocket.address_family = this.AddressFamily;
acceptSocket.socket_type = this.SocketType;
return; */
}
}
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ static extern void cancel_blocking_socket_operation (Thread thread);
protected virtual void Dispose (bool disposing)
{
IntPtr x = socket;
socket = (IntPtr) (-1);
Thread th = blocking_thread;
- if (th != null) {
- th.Abort ();
- blocking_thread = null;
- }
+ blocking_thread = null;
+ if (th != null)
+ cancel_blocking_socket_operation (th);
if (was_connected)
Linger (x);
int error = 0;
- blocking_thread = Thread.CurrentThread;
try {
+ blocking_thread = Thread.CurrentThread;
Connect_internal (socket, serial, out error);
- } catch (ThreadAbortException) {
- if (disposed) {
- Thread.ResetAbort ();
- error = (int) SocketError.Interrupted;
- }
} finally {
blocking_thread = null;
}
if (error == 0 || error == 10035)
seed_endpoint = remoteEP; // Keep the ep around for non-blocking sockets
- if (error != 0)
+ if (error != 0) {
+ if (closed)
+ error = SOCKET_CLOSED;
throw new SocketException (error);
+ }
#if !MOONLIGHT
if (socket_type == SocketType.Dgram && (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any)))
// FIXME: this is canceling a synchronous connect, not an async one
Socket s = e.ConnectSocket;
- if ((s != null) && (s.blocking_thread != null))
- s.blocking_thread.Abort ();
+ if (s != null) {
+ Thread th = s.blocking_thread;
+ blocking_thread = null;
+ if (th != null)
+ cancel_blocking_socket_operation (th);
+ }
+ }
}
#endif
[MethodImplAttribute (MethodImplOptions.InternalCall)]