Пример #1
0
        static async Task ProcessAddInteger()
        {
            var listener = await transportFactory.BindAsync(new IPEndPoint(IPAddress.Loopback, 5005));

            while (true)
            {
                var connection = await listener.AcceptAsync();

                MultiplexingSocketProtocol <AddIntegerRequest, int> protocol = new MultiplexingSocketProtocol <AddIntegerRequest, int>(connection, new AddIntegerRequestReader(), new AddIntegerResponseWritter(), new Int32MessageIdGenerator(), new Int32MessageIdParser());
                _ = Task.Run(async() => { await ProcessProtocol(protocol); });
            }
        }
        public async ValueTask <TransportFactoryBindResult> TryBindAsync(EndPoint endpoint, CancellationToken cancellationToken = default)
        {
            if (endpoint is FileHandleEndPoint ||
                endpoint is UnixDomainSocketEndPoint ||
                (endpoint is IPEndPoint ipEndPoint &&
                 ipEndPoint.Port != 0))                //  a port of 0 indicates an extension endpoint masquerading as an IPEndPoint to avoid Kestrel throwing exceptions
            {
                return(new TransportFactoryBindResult(
                           true, endpoint, await _factory.BindAsync(endpoint, cancellationToken)
                           ));
            }

            return(new TransportFactoryBindResult(endpoint));
        }
 public async Task ThrowsNotImplementedExceptionWhenBindingToUriEndPoint()
 {
     var socketTransportFactory = new SocketTransportFactory(Options.Create(new SocketTransportOptions()), new LoggerFactory());
     await Assert.ThrowsAsync <NotImplementedException>(async() => await socketTransportFactory.BindAsync(new UriEndPoint(new Uri("http://127.0.0.1:5554"))));
 }
Пример #4
0
 public async Task ThrowsNotSupportedExceptionWhenBindingToFileHandleEndPoint()
 {
     var socketTransportFactory = new SocketTransportFactory(Options.Create(new SocketTransportOptions()), Mock.Of <ILoggerFactory>());
     await Assert.ThrowsAsync <NotSupportedException>(async() => await socketTransportFactory.BindAsync(new FileHandleEndPoint(0, FileHandleType.Auto)));
 }