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); }
private Stream Request(Uri aUri, int aPriority) { HttpClientSession session = new HttpClientSession(aUri); Add(session, aPriority); return(session.Wait()); }
private void Add(HttpClientSession aSession, int aPriority) { lock (iSessions) { iSessions[aPriority].Add(aSession); iSemaphore.Set(); } }
public ClientSession(StreamSocket clientSocket) { if (clientSocket == null) { throw new ArgumentNullException(nameof(clientSocket)); } _clientSocket = clientSocket; _httpClientSession = new HttpClientSession(clientSocket, _cancellationTokenSource, HandleHttpRequest, UpgradeToWebSocketSession); }
private HttpClientSession GetNextSession() { foreach (List <HttpClientSession> list in iSessions) { if (list.Count > 0) { HttpClientSession session = list[0]; list.RemoveAt(0); return(session); } } return(null); }
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(); } } }