public void Connect(EndPoint ep, IOArgs args = null) { if (Disposed) { throw new ObjectDisposedException(""); } if (Connected) { throw new SocketException((int)SocketError.IsConnected); } IOArgs connectArgs = args == null?IOArgs.Alloc() : args; connectArgs.RemoteEndPoint = ep; connectArgs.Handler = this; try { if (!_socket.ConnectAsync(connectArgs)) { SubmitIO(connectArgs); } } catch (Exception ex) { if (args == null) { connectArgs.Dispose(); } throw ex; } }
public void Accept(IOArgs args = null) { if (Disposed) { throw new ObjectDisposedException(""); } IOArgs acceptArgs = args = args == null?IOArgs.Alloc() : args; acceptArgs.Handler = this; try { if (!_socket.AcceptAsync(acceptArgs)) { SubmitIO(acceptArgs); } } catch (Exception ex) { if (args == null) { acceptArgs.Dispose(); } throw ex; } }
public void Send(string str) { IOArgs args = IOArgs.Alloc(); args.SetBuffer(str); try { if (!_socket.SendAsync(args)) { SubmitIO(args); } } catch (Exception ex) { args.Dispose(); throw ex; } }
protected override void OnAccept(IOArgs args) { EchoConnection connection = new EchoConnection(args.AcceptSocket); try { IOArgs receiveArgs = IOArgs.Alloc(); //Allocate args connection.DoReceive(receiveArgs); } catch (Exception) { connection.Dispose(); } //AcceptSocket, must be null/non connected socket. args.AcceptSocket = null; Accept(args); }
public void Disconnect(IOArgs args = null) { if (Disposed) { throw new ObjectDisposedException(""); } if (!Connected) { throw new SocketException((int)SocketError.NotConnected); } _socket.Shutdown(SocketShutdown.Both); IOArgs diconnectArgs = args == null?IOArgs.Alloc(this) : args; diconnectArgs.DisconnectReuseSocket = true; diconnectArgs.Handler = this; try { if (!_socket.DisconnectAsync(diconnectArgs)) { SubmitIO(diconnectArgs); } } catch (Exception ex) { if (args == null) { diconnectArgs.Dispose(); } throw ex; } }