/// <summary> /// Create an uninitialized server instance. /// To start the server listening for connection requests /// call the Init method followed by Start method. /// </summary> /// <param name="numConnections">Maximum number of connections to be handled simultaneously.</param> /// <param name="bufferSize">Buffer size to use for each socket I/O operation.</param> internal SocketListener(Int32 numConnections, Int32 bufferSize, List<IProcessor> headerprocessors) { HeaderProcessors = headerprocessors; this.numConnections = numConnections; this.bufferSize = bufferSize; this.readWritePool = new SocketAsyncEventArgsPool(numConnections); this.semaphoreAcceptedClients = new Semaphore(numConnections, numConnections); // Preallocate pool of SocketAsyncEventArgs objects. for (Int32 i = 0; i < this.numConnections; i++) { SocketAsyncEventArgs readWriteEventArg = new SocketAsyncEventArgs(); readWriteEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(OnIOCompleted); //byte[] buffer = new byte readWriteEventArg.SetBuffer(new Byte[this.bufferSize], 0, this.bufferSize); // Add SocketAsyncEventArg to the pool. this.readWritePool.Push(readWriteEventArg); } }
/// <summary> /// Create an uninitialized server instance. /// To start the server listening for connection requests /// call the Init method followed by Start method. /// </summary> /// <param name="numConnections">Maximum number of connections to be handled simultaneously.</param> /// <param name="bufferSize">Buffer size to use for each socket I/O operation.</param> internal SocketListener(Int32 numConnections, Int32 bufferSize, List <IProcessor> headerprocessors) { HeaderProcessors = headerprocessors; this.numConnections = numConnections; this.bufferSize = bufferSize; this.readWritePool = new SocketAsyncEventArgsPool(numConnections); this.semaphoreAcceptedClients = new Semaphore(numConnections, numConnections); // Preallocate pool of SocketAsyncEventArgs objects. for (Int32 i = 0; i < this.numConnections; i++) { SocketAsyncEventArgs readWriteEventArg = new SocketAsyncEventArgs(); readWriteEventArg.Completed += new EventHandler <SocketAsyncEventArgs>(OnIOCompleted); //byte[] buffer = new byte readWriteEventArg.SetBuffer(new Byte[this.bufferSize], 0, this.bufferSize); // Add SocketAsyncEventArg to the pool. this.readWritePool.Push(readWriteEventArg); } }