예제 #1
0
        protected override async Task<TClientTransport> AcceptImplementationAsync(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return await Task.FromCanceled<TClientTransport>(cancellationToken);
            }

            if (_server == null)
            {
                throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
            }

            try
            {
                TSocketClientTransport tSocketTransport = null;
                var tcpClient = await _server.AcceptTcpClientAsync();

                try
                {
                    tSocketTransport = new TSocketClientTransport(tcpClient)
                    {
                        Timeout = _clientTimeout
                    };

                    if (_useBufferedSockets)
                    {
                        return new TBufferedClientTransport(tSocketTransport);
                    }

                    return tSocketTransport;
                }
                catch (Exception)
                {
                    if (tSocketTransport != null)
                    {
                        tSocketTransport.Dispose();
                    }
                    else //  Otherwise, clean it up ourselves.
                    {
                        ((IDisposable) tcpClient).Dispose();
                    }

                    throw;
                }
            }
            catch (Exception ex)
            {
                throw new TTransportException(ex.ToString());
            }
        }
예제 #2
0
파일: TestClient.cs 프로젝트: nsuke/thrift
            public TClientTransport CreateTransport()
            {
                if (url == null)
                {
                    // endpoint transport
                    TClientTransport trans = null;

                    if (pipe != null)
                    {
                        trans = new TNamedPipeClientTransport(pipe);
                    }
                    else
                    {
                        if (encrypted)
                        {
                            var certPath = "../../keys/client.p12";
                            var cert = new X509Certificate2(certPath, "thrift");
                            trans = new TTlsSocketClientTransport(host, port, 0, cert, (o, c, chain, errors) => true, null, SslProtocols.Tls);
                        }
                        else
                        {
                            trans = new TSocketClientTransport(host, port);
                        }
                    }

                    // layered transport
                    if (buffered)
                    {
                        trans = new TBufferedClientTransport(trans);
                    }

                    if (framed)
                    {
                        trans = new TFramedClientTransport(trans);
                    }

                    return trans;
                }

                return new THttpClientTransport(new Uri(url), null);
            }