void Complete(SocketAsyncEventArgs e, bool completeSynchronously) { TransportBase transport = null; Exception exception = null; if (e.SocketError != SocketError.Success) { exception = new SocketException((int)e.SocketError); if (e.AcceptSocket != null) { e.AcceptSocket.Dispose(); } } else { try { Fx.Assert(e.ConnectSocket != null, "Must have a valid socket accepted."); e.ConnectSocket.NoDelay = true; transport = new TcpTransport(e.ConnectSocket, this.transportSettings); transport.Open(); } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } exception = exp; if (transport != null) { transport.SafeClose(); } transport = null; } } e.Dispose(); this.callbackArgs.CompletedSynchronously = completeSynchronously; this.callbackArgs.Exception = exception; this.callbackArgs.Transport = transport; if (!completeSynchronously) { this.callbackArgs.CompletedCallback(this.callbackArgs); } }
public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs) { var streamSocket = new Windows.Networking.Sockets.StreamSocket(); var addr = this.transportSettings.Host; this.callbackArgs = callbackArgs; var connectTask = streamSocket.ConnectAsync(new Windows.Networking.HostName(addr), this.transportSettings.Port.ToString(), Windows.Networking.Sockets.SocketProtectionLevel.PlainSocket).AsTask(); connectTask.ContinueWith(_ => { TransportBase transport = null; Exception exception = null; try { transport = new TcpTransport(streamSocket, this.transportSettings); transport.Open(); } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } exception = exp; if (transport != null) { transport.SafeClose(); } transport = null; } var completeSynchronously = false; this.callbackArgs.CompletedSynchronously = completeSynchronously; this.callbackArgs.Exception = exception; this.callbackArgs.Transport = transport; if (!completeSynchronously) { this.callbackArgs.CompletedCallback(this.callbackArgs); } }); return(true); }
public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs) { var streamSocket = new Windows.Networking.Sockets.StreamSocket(); var addr = this.transportSettings.Host; this.callbackArgs = callbackArgs; var connectTask = streamSocket.ConnectAsync(new Windows.Networking.HostName(addr), this.transportSettings.Port.ToString(), Windows.Networking.Sockets.SocketProtectionLevel.PlainSocket).AsTask(); connectTask.ContinueWith(_ => { TransportBase transport = null; Exception exception = null; try { transport = new TcpTransport(streamSocket, this.transportSettings); transport.Open(); } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } exception = exp; if (transport != null) { transport.SafeClose(); } transport = null; } var completeSynchronously = false; this.callbackArgs.CompletedSynchronously = completeSynchronously; this.callbackArgs.Exception = exception; this.callbackArgs.Transport = transport; if (!completeSynchronously) { this.callbackArgs.CompletedCallback(this.callbackArgs); } }); return true; }
void Complete(SocketAsyncEventArgs e, bool completeSynchronously) { TransportBase transport = null; Exception exception = null; if (e.SocketError != SocketError.Success) { exception = new SocketException((int)e.SocketError); if (e.AcceptSocket != null) { e.AcceptSocket.Dispose(); } } else { try { Fx.Assert(e.ConnectSocket != null, "Must have a valid socket accepted."); e.ConnectSocket.NoDelay = true; transport = new TcpTransport(e.ConnectSocket, this.transportSettings); transport.Open(); } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } exception = exp; if (transport != null) { transport.SafeClose(); } transport = null; } } e.Dispose(); this.callbackArgs.CompletedSynchronously = completeSynchronously; this.callbackArgs.Exception = exception; this.callbackArgs.Transport = transport; if (!completeSynchronously) { this.callbackArgs.CompletedCallback(this.callbackArgs); } }