예제 #1
0
        public async Task <Http2LoopbackConnection> AcceptConnectionAsync(TimeSpan?timeout)
        {
            RemoveInvalidConnections();

            if (!AllowMultipleConnections && _connections.Count != 0)
            {
                throw new InvalidOperationException("Connection already established. Set `AllowMultipleConnections = true` to bypass.");
            }

            Socket connectionSocket = await _listenSocket.AcceptAsync().ConfigureAwait(false);

            var stream = new NetworkStream(connectionSocket, ownsSocket: true);
            Http2LoopbackConnection connection =
                timeout != null ? await Http2LoopbackConnection.CreateAsync(connectionSocket, stream, _options, timeout.Value).ConfigureAwait(false) :
                await Http2LoopbackConnection.CreateAsync(connectionSocket, stream, _options).ConfigureAwait(false);

            _connections.Add(connection);

            return(connection);
        }
예제 #2
0
 public override async Task <GenericLoopbackConnection> CreateConnectionAsync(SocketWrapper socket, Stream stream, GenericLoopbackOptions options = null)
 {
     return(await Http2LoopbackConnection.CreateAsync(socket, stream, CreateOptions(options)).ConfigureAwait(false));
 }