public void Complete ()
{
if (operation != SocketOperation.Receive && Sock.disposed)
delayedException = new ObjectDisposedException (Sock.GetType ().ToString ());
IsCompleted = true;
Queue queue = null;
if (operation == SocketOperation.Receive ||
operation == SocketOperation.ReceiveFrom ||
operation == SocketOperation.ReceiveGeneric) {
queue = Sock.readQ;
} else if (operation == SocketOperation.Send ||
operation == SocketOperation.SendTo ||
operation == SocketOperation.SendGeneric) {
queue = Sock.writeQ;
}
if (queue != null) {
Worker worker = null;
SocketAsyncCall sac = null;
lock (queue) {
// queue.Count will only be 0 if the socket is closed while receive/send
// operation(s) are pending and at least one call to this method is
// waiting on the lock while another one calls CompleteAllOnDispose()
if (queue.Count > 0)
queue.Dequeue (); // remove ourselves
if (queue.Count > 0) {
worker = (Worker) queue.Peek ();
if (!Sock.disposed) {
sac = GetDelegate (worker, worker.result.operation);
} else {
CompleteAllOnDispose (queue);
}
}
}
if (sac != null)
Socket.socket_pool_queue (sac, worker.result);
}
// IMPORTANT: 'callback', if any is scheduled from unmanaged code
}