public HttpServiceControler() { _syncObject = new object(); _listeners = new List <Listener>(); _processorFactory = new ProcessorFactory(); _sessions = new Dictionary <string, ServerSession>(); //read config HttpServiceConfigSection config = HttpServiceConfigSection.Instance; _maxConnections = config.Connection.ConnectionsLimit; _serverKeepAlive = config.Connection.KeepAlive; _keepAliveTimeout = config.Connection.Timeout; //add binds foreach (BindConfigElement bind in config.Binds) { Listener listener = new Listener(bind.ToEndPoint(), bind.Name); listener.NewConnectionAccepted += new EventHandler <AcceptNewConnectionEventArgs>(listener_NewConnectionAccepted); _listeners.Add(listener); } //timer for scan idle connections if (_serverKeepAlive) { _scanTimer = new System.Timers.Timer(SCAN_TIME_INTERVAL); _scanTimer.AutoReset = true; _scanTimer.Elapsed += new System.Timers.ElapsedEventHandler(removeIdle); _scanTimer.Start(); } }
public ServerSession( System.Net.Sockets.Socket workSocket, System.Net.IPEndPoint bindEndPoint, string bindEndPointName, bool serverKeepAlive, ProcessorFactory processorFactory) { workSocket.NoDelay = true; //donot use Nagle _clientIp = ((System.Net.IPEndPoint)workSocket.RemoteEndPoint).Address; _bindEndPoint = bindEndPoint; _bindEndPointName = bindEndPointName; _serverKeepAlive = serverKeepAlive; _processorFactory = processorFactory; _session = new AsyncSocketSession(workSocket); _session.ConnectionClose += new EventHandler <ConnectionCloseEventArgs>(session_ConnectionClose); _session.SendComplete += new EventHandler <SendCompleteEventArgs>(session_SendComplete); _session.ReceiveHeaderComplete += new EventHandler <ReceiveHeaderCompleteEventArgs>(session_ReceiveHeaderComplete); _session.ReceiveBodyComplete += new EventHandler <ReceiveBodyCompleteEventArgs>(session_ReceiveBodyComplete); _connectionToken = System.Guid.NewGuid().ToString("N"); _bodyBuffer = new byte[BODY_BUFFER_LENGTH]; //set the active time _lastActiveTime = DateTime.Now; }