示例#1
0
    public InMemoryConnection CreateConnection(Encoding encoding = null)
    {
        var transportConnection = new InMemoryTransportConnection(_memoryPool, Context.Log, Context.Scheduler);

        _transportFactory.AddConnection(transportConnection);
        return(new InMemoryConnection(transportConnection, encoding));
    }
示例#2
0
    public async ValueTask <ConnectionContext> ConnectAsync(EndPoint endpoint, CancellationToken cancellationToken = default)
    {
        var listener = _hub.GetConnectionListenerFactory(endpoint);

        if (listener is null)
        {
            throw new ConnectionFailedException($"Unable to connect to endpoint {endpoint} because no such endpoint is currently registered.");
        }

        var connectionContext = InMemoryTransportConnection.Create(
            _memoryPool.Pool,
            _loggerFactory.CreateLogger <InMemoryTransportConnection>(),
            _localEndpoint,
            endpoint);
        await listener.ConnectAsync(connectionContext).WithCancellation(cancellationToken);

        return(connectionContext);
    }
示例#3
0
 public InMemoryConnection(InMemoryTransportConnection transportConnection, Encoding encoding)
     : base(new DuplexPipeStream(transportConnection.Output, transportConnection.Input), encoding)
 {
     TransportConnection = transportConnection;
 }