Inheritance: System.EventArgs
Esempio n. 1
0
        private IEnumerator<object> KeepAliveTask(ListenerContext context, IncomingConnection incomingConnection)
        {
            var socket = incomingConnection.Socket;
            EndPoint localEp = socket.LocalEndPoint, remoteEp = socket.RemoteEndPoint;
            var evtArgs = new ConnectionEventArgs(localEp, remoteEp);

            var keepAliveStarted = DateTime.UtcNow;

            if (SocketOpened != null)
                SocketOpened(this, evtArgs);

            int requestCount = 0;

            try {
                using (var adapter = new SocketDataAdapter(socket, true)) {
                    while (!adapter.IsDisposed && adapter.Socket.Connected) {
                        var fTask = Scheduler.Start(RequestTask(context, adapter));
                        yield return fTask;

                        requestCount += 1;

                        if (fTask.Failed) {
                            adapter.Dispose();
                            yield break;
                        }
                    }
                }
            } finally {
                var keepAliveEnded = DateTime.UtcNow;

                if (SocketClosed != null)
                    SocketClosed(this, evtArgs);

                if (Trace != null)
                    Trace(
                        String.Format(
                            "KA_START {0:0000.0}ms  KA_LENGTH {1:00000.0}ms  {2} REQ(S)",
                            (keepAliveStarted - incomingConnection.AcceptedWhenUTC).TotalMilliseconds,
                            (keepAliveEnded - keepAliveStarted).TotalMilliseconds,
                            requestCount
                        )
                    );
            }
        }
Esempio n. 2
0
 static void OnSocketOpened(object server, ConnectionEventArgs e)
 {
     Console.WriteLine("{0} <- {1} open", e.LocalEndPoint, e.RemoteEndPoint);
 }