Exemple #1
0
        /// <summary>
        /// 构造函数,建立一个未初始化的服务器实例
        /// </summary>
        /// <param name="numMaxConnections">服务器的最大连接数据</param>
        /// <param name="bufferSize"></param>
        public IocpServer(Int32 numMaxConnections, Int32 bufferSize)
        {
            this.numConnectedSockets = 0;
            this.numMaxConnections = numMaxConnections;
            this.bufferSize = bufferSize;

            this.ioContextPool = new IoContextPool(numMaxConnections);

            // 为IoContextPool预分配SocketAsyncEventArgs对象
            for (Int32 i = 0; i < this.numMaxConnections; i++)
            {
                SocketAsyncEventArgs readWriteArgs = new SocketAsyncEventArgs();
                readWriteArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnIOCompleted);
                readWriteArgs.SetBuffer(new Byte[this.bufferSize], 0, this.bufferSize);

                // 将预分配的对象加入SocketAsyncEventArgs对象池中
                this.ioContextPool.Add(readWriteArgs);
            }
        }
Exemple #2
0
        /// <summary>
        /// 构造函数,建立一个未初始化的服务器实例
        /// </summary>
        /// <param name="numConnections">服务器的最大连接数据</param>
        /// <param name="bufferSize"></param>
        internal IoServer(Int32 numConnections, Int32 bufferSize)
        {
            this.numConnectedSockets = 0;
            this.numConnections      = numConnections;
            this.bufferSize          = bufferSize;

            this.ioContextPool = new IoContextPool(numConnections);

            // 为IoContextPool预分配SocketAsyncEventArgs对象
            for (Int32 i = 0; i < this.numConnections; i++)
            {
                SocketAsyncEventArgs ioContext = new SocketAsyncEventArgs();
                ioContext.Completed += new EventHandler <SocketAsyncEventArgs>(OnIOCompleted);
                ioContext.SetBuffer(new Byte[this.bufferSize], 0, this.bufferSize);

                // 将预分配的对象加入SocketAsyncEventArgs对象池中
                this.ioContextPool.Add(ioContext);
            }
        }
        /// <summary>
        /// 构造函数,建立一个未初始化的服务器实例
        /// </summary>
        /// <param name="numMaxConnections">服务器的最大连接数据</param>
        /// <param name="bufferSize"></param>
        public IocpServer(Int32 numMaxConnections, Int32 bufferSize)
        {
            this.numConnectedSockets = 0;
            this.numMaxConnections   = numMaxConnections;
            this.bufferSize          = bufferSize;

            this.ioContextPool = new IoContextPool(numMaxConnections);

            // 为IoContextPool预分配SocketAsyncEventArgs对象
            for (Int32 i = 0; i < this.numMaxConnections; i++)
            {
                SocketAsyncEventArgs readWriteArgs = new SocketAsyncEventArgs();
                readWriteArgs.Completed += new EventHandler <SocketAsyncEventArgs>(OnIOCompleted);
                readWriteArgs.SetBuffer(new Byte[this.bufferSize], 0, this.bufferSize);

                // 将预分配的对象加入SocketAsyncEventArgs对象池中
                this.ioContextPool.Add(readWriteArgs);
            }
        }