/// <summary> /// /// </summary> /// <param name="receiveHandle"></param> /// <returns></returns> public async Task <UdpRemote> ListenAsync(IReceiveCallbackMgr callbackMgr) { IsListening = true; System.Threading.ThreadPool.QueueUserWorkItem(state => { AcceptAsync(); }); if (connected.TryDequeue(out var remote)) { if (remote != null) { remote.ReceiveStart(); return(remote); } } if (TaskCompletionSource == null) { TaskCompletionSource = new TaskCompletionSource <UdpRemote>(); } var res = await TaskCompletionSource.Task; TaskCompletionSource = null; res.ReceiveCallbackMgr = callbackMgr; res.ReceiveStart(); return(res); }
public async Task <TcpRemote> ListenAsync(IReceiveCallbackMgr callbackMgr) { var remoteSocket = await Accept(); var remote = new TcpRemote(remoteSocket); remote.ReceiveCallbackMgr = callbackMgr; remote.ReceiveStart(); return(remote); }