public WebServer(int port, bool localOnly, ReqRespHandler<HttpRequest, HttpResponse> reqHandler)
        {
            this.reqHandler = reqHandler;

            int maxNumberOfConnections = 1000;
            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 = this.contextPool.Pop();
                    context.BindSocket(clientSocket); //*** bind to client socket 
                    context.StartReceive(); //start receive data
                });
        }
 public NewConnectionListener(NewConnListenerSettings setting, Action<Socket> acceptNewConnectionHandler)
 {
     this.setting = setting;
     this.acceptArgsPool = new SharedResoucePool<SocketAsyncEventArgs>(this.setting.MaxAcceptOps);
     this.acceptNewConnectionHandler = acceptNewConnectionHandler;
     // Create connections count enforcer
     this.maxConnEnforcer = new Semaphore(this.setting.MaxConnections, this.setting.MaxConnections);
 }
Exemple #3
0
 public NewConnectionListener(NewConnListenerSettings setting, Action <Socket> acceptNewConnectionHandler)
 {
     this.setting                    = setting;
     this.acceptArgsPool             = new SharedResoucePool <SocketAsyncEventArgs>(this.setting.MaxAcceptOps);
     this.acceptNewConnectionHandler = acceptNewConnectionHandler;
     // Create connections count enforcer
     this.maxConnEnforcer = new Semaphore(this.setting.MaxConnections, this.setting.MaxConnections);
 }