protected override async Task <StopReason> DoProcess(CancellationToken cancel_token) { try { var keep_count = 1000; while (!cancel_token.IsCancellationRequested && keep_count-- > 0) { HttpRequest req; using (var requestTimeout = CancellationTokenSource.CreateLinkedTokenSource(cancel_token)) using (var reader = new HttpRequestReader(Connection, true)) { requestTimeout.CancelAfter(7000); req = await reader.ReadAsync(requestTimeout.Token).ConfigureAwait(false); if (req == null) { return(StopReason.OffAir); } } var ctx = new OwinContext(PeerCast, req, Connection, LocalEndPoint as IPEndPoint, RemoteEndPoint as IPEndPoint, AccessControlInfo); try { await ctx.Invoke(owinHost.OwinApp, cancel_token).ConfigureAwait(false); } catch (Exception ex) { Logger.Error(ex); return(StopReason.NotIdentifiedError); } if (!ctx.IsKeepAlive) { break; } } } catch (OperationCanceledException) { } return(StopReason.OffAir); }
public Task Invoke( HttpRequest req, ConnectionStream stream, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, AccessControlInfo accessControlInfo, CancellationToken cancellationToken) { var ctx = new OwinContext(PeerCast, req, stream, localEndPoint, remoteEndPoint, accessControlInfo); return(ctx.Invoke(OwinApp, cancellationToken)); }