public void Stop() { _newConnListener.DisposePool(); while (_contextPool.Count > 0) { _contextPool.Pop().Dispose(); } }
public void Start() { if (_isRunning) { return; } //------------------------------ try { int maxNumberOfConnections = 500; int excessSaeaObjectsInPool = 200; int backlog = 100; int maxSimultaneousAcceptOps = 100; var setting = new NewConnListenerSettings(maxNumberOfConnections, excessSaeaObjectsInPool, backlog, maxSimultaneousAcceptOps, new IPEndPoint(_localOnly ? IPAddress.Loopback : IPAddress.Any, _port));//check only local host or not CreateContextPool(maxNumberOfConnections); _newConnListener = new NewConnectionListener(setting, clientSocket => { //when accept new client HttpContext context = _contextPool.Pop(); context.BindSocket(clientSocket); //*** bind to client socket context.StartReceive(); //start receive data }); //start web server _isRunning = true; _newConnListener.StartListening(); } catch (Exception ex) { } }