예제 #1
0
        private IEnumerator <object> ListenerTask(ListenerContext context)
        {
            using (context) {
                yield return(Future.RunInThread(context.Start));

                var       wfns = new WaitForNextStep();
                var       acceptedConnections                  = new List <IncomingConnection>();
                const int connectionsToAcceptPerStep           = 4;
                Future <IncomingConnection> acceptedConnection = null;

                while (true)
                {
                    if (acceptedConnection != null)
                    {
                        if (acceptedConnection.Failed)
                        {
                            OnListenerError(acceptedConnection.Error);
                        }
                        else
                        {
                            acceptedConnections.Add(acceptedConnection.Result);
                        }
                    }

                    context.IncomingConnections.DequeueMultiple(
                        acceptedConnections, connectionsToAcceptPerStep
                        );

                    foreach (var ac in acceptedConnections)
                    {
                        var fKeepAlive = Scheduler.Start(KeepAliveTask(context, ac));
                        fKeepAlive.RegisterOnComplete(RequestOnComplete);
                    }

                    acceptedConnections.Clear();
                    acceptedConnection = context.IncomingConnections.Dequeue();

                    yield return(acceptedConnection);
                }
            }
        }
예제 #2
0
파일: HttpServer.cs 프로젝트: sq/Fracture
        private IEnumerator<object> ListenerTask(ListenerContext context)
        {
            using (context) {
                yield return Future.RunInThread(context.Start);

                var wfns = new WaitForNextStep();
                var acceptedConnections = new List<IncomingConnection>();
                const int connectionsToAcceptPerStep = 4;
                Future<IncomingConnection> acceptedConnection = null;

                while (true) {
                    if (acceptedConnection != null) {
                        if (acceptedConnection.Failed)
                            OnListenerError(acceptedConnection.Error);
                        else
                            acceptedConnections.Add(acceptedConnection.Result);
                    }

                    context.IncomingConnections.DequeueMultiple(
                        acceptedConnections, connectionsToAcceptPerStep
                    );

                    foreach (var ac in acceptedConnections) {
                        var fKeepAlive = Scheduler.Start(KeepAliveTask(context, ac));
                        fKeepAlive.RegisterOnComplete(RequestOnComplete);
                    }

                    acceptedConnections.Clear();
                    acceptedConnection = context.IncomingConnections.Dequeue();

                    yield return acceptedConnection;
                }
            }
        }