public Task <IConn> Accept() { if (_incoming.TryDequeue(out var conn)) { return(Task.FromResult <IConn>(conn)); } if (_poll != null) { throw new IOException("There is a wait already"); } _poll = _proc.Promise <IConn>(Timeout.InfiniteTimeSpan, _proc.Token); return(_poll.Task); }
public async Task <SimPacket> Read(TimeSpan timeout) { if (_closed) { throw new IOException("Socket closed"); } if (_readBuffer.TryDequeue(out var tuple)) { if (tuple.Flag == SimFlag.Reset) { Close("RESET"); throw new IOException("Connection reset"); } if (NextIsFin()) { Close("FIN"); } return(tuple); } _pendingRead = _proc.Promise <SimPacket>(timeout, _proc.Token); var msg = await _pendingRead.Task; if (msg.Flag == SimFlag.Reset) { Close("RESET"); throw new IOException("Connection reset"); } if (NextIsFin()) { Close("FIN"); } return(msg); }