internal async Task _Listener() { while (_cancel.IsCancellationRequested == false) { var soc = await _listen.AcceptAsyncEx(); Task.Run(async() => { try { soc.SetKeepAlive(); var buf = await soc.ReceiveAsyncExt().TimeoutAfter("Timeout, at receive header packet."); var pkt = new LinkPacket().LoadValue(buf); await _requested.Invoke(soc, pkt); } catch (Exception ex) { Log.Error(ex); } finally { soc.Dispose(); } }).Ignore(); } }
private async Task _Listen() { void _Invoke(Socket soc) => Task.Run(async() => { try { _ = soc.SetKeepAlive(); await await _AcceptClient(soc); } finally { soc.Dispose(); } }); while (true) { _Invoke(await _socket.AcceptAsyncEx()); } }