private void OnConnect(object sender, SocketAsyncEventArgs e) { if (e.SocketError != SocketError.Success) { _connectCompletionSource.SetException(new SocketException((int)e.SocketError)); _connectCompletionSource = null; return; } try { if (_channel == null) { _channel = CreateChannel(); } _channel.Assign(_socket); } catch (Exception exception) { _connectCompletionSource.SetException(exception); _connectCompletionSource = null; return; } _connectCompletionSource.SetResult((IPEndPoint)_socket.RemoteEndPoint); _connectCompletionSource = null; }
private void OnConnect(object sender, SocketAsyncEventArgs e) { if (e.SocketError != SocketError.Success) { _connectException = new SocketException((int)e.SocketError); _socket = null; } _channel.Assign(_socket); _connectSemaphore.Release(); }