// This method is called whenever a receive or send operation is completed on a socket // // <param name="e">SocketAsyncEventArg associated with the completed receive operation</param> void IO_Completed(object sender, SocketAsyncEventArgs e1) { SocketRect e = e1 as SocketRect; // determine which type of operation just completed and call the associated handler switch (e.LastOperation) { case SocketAsyncOperation.Receive: ProcessReceive(e as T); break; case SocketAsyncOperation.Send: ProcessSend(e1 as SocketWrite); break; case SocketAsyncOperation.Accept: break; case SocketAsyncOperation.Connect: e.ConnectAction?.Invoke(e, true); if (!((Socket)e.UserToken).ReceiveAsync(e)) { ProcessReceive(e as T); } break; case SocketAsyncOperation.Disconnect: e.ConnectAction?.Invoke(e, false); break; case SocketAsyncOperation.None: break; case SocketAsyncOperation.ReceiveFrom: break; case SocketAsyncOperation.ReceiveMessageFrom: break; case SocketAsyncOperation.SendPackets: break; case SocketAsyncOperation.SendTo: break; default: throw new ArgumentException("The last operation completed on the socket was not a receive or send"); } }
public SocketWrite(SocketRect sk) { ReacSocket = sk; this.UserToken = null; }