private static void SendDirectRequest(RequestHandler requestHandler, PeerConnection peerConnection) { var taskCc = peerConnection.AcquireAsync(requestHandler.TcsResponse); taskCc.ContinueWith(tcc => { if (!tcc.IsFaulted) { var requestMessage = requestHandler.TcsResponse.Task.AsyncState as Message.Message; requestMessage.SetKeepAlive(true); requestHandler.SendTcpAsync(peerConnection.ChannelCreator, peerConnection); } else { requestHandler.TcsResponse.SetException(new TaskFailedException("Could not acquire channel (2).", tcc)); } }); }
private Task <PeerAddress> PingPeerConnection(PeerConnection peerConnection) { var tcsPing = new TaskCompletionSource <PeerAddress>(); var requestHandler = _peer.PingRpc.Ping(peerConnection.RemotePeer, _connectionConfiguration); var taskCc = peerConnection.AcquireAsync(requestHandler.TcsResponse); taskCc.ContinueWith(tcc => { if (!tcc.IsFaulted) { requestHandler.TcsResponse.Task.Result.SetKeepAlive(true); // TODO correct? var taskResponse = requestHandler.SendTcpAsync(peerConnection); AddPingListener(tcsPing, taskResponse); } else { tcsPing.SetException(tcc.TryGetException()); } }); return(tcsPing.Task); }
private Task<PeerAddress> PingPeerConnection(PeerConnection peerConnection) { var tcsPing = new TaskCompletionSource<PeerAddress>(); var requestHandler = _peer.PingRpc.Ping(peerConnection.RemotePeer, _connectionConfiguration); var taskCc = peerConnection.AcquireAsync(requestHandler.TcsResponse); taskCc.ContinueWith(tcc => { if (!tcc.IsFaulted) { requestHandler.TcsResponse.Task.Result.SetKeepAlive(true); // TODO correct? var taskResponse = requestHandler.SendTcpAsync(peerConnection); AddPingListener(tcsPing, taskResponse); } else { tcsPing.SetException(tcc.TryGetException()); } }); return tcsPing.Task; }