Esempio n. 1
0
        internal async Task RemoveConnection(RelayConnection conn)
        {
            await _lock.WaitAsync().ConfigureAwait(false);

            try
            {
                _connections.Remove(conn);
            }
            finally { _lock.Release(); }
        }
Esempio n. 2
0
        internal async Task AcceptAsync(HttpContext context)
        {
            WebSocketClient socket;

            try
            {
                socket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);
            }
            catch { return; }

            var _ = Task.Run(async() =>
            {
                var conn = new RelayConnection(this, socket, Interlocked.Increment(ref _nextId));
                await AddConnection(conn).ConfigureAwait(false);
                try
                {
                    await conn.RunAsync().ConfigureAwait(false);
                }
                finally { await RemoveConnection(conn).ConfigureAwait(false); }
            });
        }