public Connection(ServicePoint servicePoint) { _state = 0; _servicePoint = servicePoint; _saea = SaeaPool.Default.GetSaea(); _buffer = BufferPool.Default.GetBuffer(); _socket = new Socket(servicePoint.HostEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _socket.NoDelay = !servicePoint.UseNagleAlgorithm; if (_servicePoint.IsSecured) { _asyncReadWrite = new SslAsyncReadWrite(servicePoint.Address.Host, _socket, _saea, servicePoint.ClientCertificate, ValidateServerCertificate); } else { _asyncReadWrite = new AsyncReadWrite(_socket, _saea); } }
public void FreeSaea(Saea saea) { saea.Free(); }
public AsyncReadWrite(Socket socket, Saea saea) { _socket = socket; _saea = saea; _saea.OnCompleted(_ => { _completed = true; var previous = _continuation ?? Interlocked.CompareExchange(ref _continuation, Sentinal, null); if (previous != null) { previous(); } }); }
public SslAsyncReadWrite(string host, Socket socket, Saea saea, X509Certificate clientCertificate, RemoteCertificateValidationCallback userCertificateValidationCallback) : base(socket, saea) { _host = host; _userCertificateValidationCallback = userCertificateValidationCallback; if (clientCertificate != null) { _clientCertificates = new X509CertificateCollection(new X509Certificate[] { clientCertificate }); } }