public TcpServerListenerAdv(int port, int maxNumConnections, int receiveBufferSize) : base(receiveBufferSize) { _maxNumConnections = maxNumConnections; // allocate buffers such that the maximum number of sockets can have one outstanding read and // write posted to the socket simultaneously _bufferManager = new BufferManager(receiveBufferSize * maxNumConnections * OpsToPreAlloc, receiveBufferSize); // allocate pool of SocketAsyncEventArgs for sending and recieveing Args objects _argsReadWritePool = new SocketAsyncEventArgsPool(maxNumConnections * OpsToPreAlloc); // set limiter of connected clients' number _maxNumberConnectedClients = new Semaphore(maxNumConnections, maxNumConnections); _port = port; //allocate resources Init(); }
Semaphore maxNumberAcceptedClients; // limit number of clients //Logger log; // log file writer public TCPServerListener(int port, int maxNumConnections, int receiveBufferSize) { this.maxNumConnections = maxNumConnections; this.receiveBufferSize = receiveBufferSize; //this.log = log; // allocate buffers such that the maximum number of sockets can have one outstanding read and // write posted to the socket simultaneously bufferManager = new BufferManager(receiveBufferSize * maxNumConnections * opsToPreAlloc, receiveBufferSize); argsReadWritePool = new SocketAsyncEventArgsPool(maxNumConnections); maxNumberAcceptedClients = new Semaphore(maxNumConnections, maxNumConnections); IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port); Init(); Logger.WriteStr("Init level completed"); Start(localEndPoint); }