Пример #1
0
        public ClientSession(StreamSocket clientSocket, ILogger log)
        {
            _clientSocket = clientSocket ?? throw new ArgumentNullException(nameof(clientSocket));
            _log          = log ?? throw new ArgumentNullException(nameof(log));

            _httpClientSession = new HttpClientSession(clientSocket, _cancellationTokenSource, HandleHttpRequest, UpgradeToWebSocketSession, _log);
        }
Пример #2
0
        private Stream Request(Uri aUri, int aPriority)
        {
            HttpClientSession session = new HttpClientSession(aUri);

            Add(session, aPriority);
            return(session.Wait());
        }
Пример #3
0
 private void Add(HttpClientSession aSession, int aPriority)
 {
     lock (iSessions)
     {
         iSessions[aPriority].Add(aSession);
         iSemaphore.Set();
     }
 }
Пример #4
0
        public ClientSession(StreamSocket clientSocket)
        {
            if (clientSocket == null)
            {
                throw new ArgumentNullException(nameof(clientSocket));
            }

            _clientSocket = clientSocket;

            _httpClientSession = new HttpClientSession(clientSocket, _cancellationTokenSource, HandleHttpRequest, UpgradeToWebSocketSession);
        }
Пример #5
0
        private HttpClientSession GetNextSession()
        {
            foreach (List <HttpClientSession> list in iSessions)
            {
                if (list.Count > 0)
                {
                    HttpClientSession session = list[0];
                    list.RemoveAt(0);
                    return(session);
                }
            }

            return(null);
        }
Пример #6
0
        private void UpgradeToWebSocketSession(UpgradedToWebSocketSessionEventArgs eventArgs)
        {
            _httpClientSession = null;

            _webSocketClientSession         = new WebSocketClientSession(_clientSocket, _log);
            _webSocketClientSession.Closed += OnWebSocketClientSessionClosed;

            var webSocketConnectedEventArgs = new WebSocketConnectedEventArgs(eventArgs.HttpRequest, _webSocketClientSession);

            try
            {
                WebSocketConnected?.Invoke(this, webSocketConnectedEventArgs);
            }
            finally
            {
                if (!webSocketConnectedEventArgs.IsHandled)
                {
                    _cancellationTokenSource.Cancel();
                }
            }
        }