Exemplo n.º 1
0
            public async ValueTask <TcpConnector> CreateAsync(TcpConnectOptions tcpConnectOptions, TcpAcceptOptions tcpAcceptOptions, IBytesPool bytesPool)
            {
                var result = new TcpConnector(tcpConnectOptions, tcpAcceptOptions, bytesPool);
                await result.InitAsync();

                return(result);
            }
Exemplo n.º 2
0
        public async Task ConnectAsyncTest()
        {
            const int    Port      = 55555;
            const string IpAddress = "127.0.0.1";

            var tcpConnectOptions = new TcpConnectOptions(true, null);
            var tcpAcceptOptions  = new TcpAcceptOptions(false, Array.Empty <OmniAddress>(), false);

            await using (var connector = await TcpConnector.Factory.CreateAsync(tcpConnectOptions, tcpAcceptOptions, BytesPool.Shared))
            {
                var tcpListener = new TcpListener(IPAddress.Parse(IpAddress), Port);

                try
                {
                    tcpListener.Start();

                    var acceptTask = tcpListener.AcceptTcpClientAsync();

                    using var cap = await connector.ConnectAsync(new OmniAddress ($"tcp(ip4(\"{IpAddress}\"),{Port})"));

                    await acceptTask;

                    Assert.NotNull(cap);

                    tcpListener.Stop();
                }
                finally
                {
                    tcpListener.Server.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        public async Task AcceptAsyncTest()
        {
            const int    port              = 55555;
            const string ipAddress         = "127.0.0.1";
            var          tcpConnectOptions = new TcpConnectOptions(false, null);
            var          tcpAcceptOptions  = new TcpAcceptOptions(true, new[] { new OmniAddress($"tcp(ip4(\"{ipAddress}\"),{port})") }, false);

            await using (var connector = await TcpConnector.Factory.CreateAsync(tcpConnectOptions, tcpAcceptOptions, BytesPool.Shared))
            {
                var acceptTask = connector.AcceptAsync();

                var tcpClient = new TcpClient();
                await tcpClient.ConnectAsync(IPAddress.Parse(ipAddress), port);

                await acceptTask;

                Assert.NotNull(acceptTask.Result.Item1);

                acceptTask.Result.Item1?.Dispose();
                tcpClient.Dispose();
            }
        }
Exemplo n.º 4
0
 internal TcpConnector(TcpConnectOptions tcpConnectOptions, TcpAcceptOptions tcpAcceptOptions, IBytesPool bytesPool)
 {
     _tcpConnectOptions = tcpConnectOptions;
     _tcpAcceptOptions  = tcpAcceptOptions;
     _bytesPool         = bytesPool;
 }