예제 #1
0
        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);
            }
            
        }
예제 #2
0
 public void FreeSaea(Saea saea)
 {
     saea.Free();
 }
예제 #3
0
 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();
         }
     });
 }
예제 #4
0
 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 });
     }               
 }