Beispiel #1
0
 public DbAccess(int num, DbType dbType)
 {
     AccesserPool = new ZObjectPool <DbAccesser>(num);
     for (int i = 0; i < AccesserPool.Count; i++)
     {
         DbAccesser dbAccesser = Create(dbType);
         if (dbAccesser != null)
         {
             AccesserPool.Push(dbAccesser);
         }
     }
 }
Beispiel #2
0
        public AsyncSocket(int numConnections)
        {
            NumConnections           = numConnections;
            ReceiveBufferSize        = 1024 * 10; // IOCP接收数据缓存大小,设置过小会造成事件响应增多,设置过大会造成内存占用偏多
            AsyncSocketUserTokenPool = new ZObjectPool <AsyncSocketUserToken>(numConnections);
            AsyncSocketUserTokenList = new ZObjectList <AsyncSocketUserToken>();
            MaxNumberAccepted        = new Semaphore(numConnections, numConnections);
            AsyncSocketUserToken userToken;
            PacketProcess        oPacketProcess = new PacketProcess();

            for (int i = 0; i < NumConnections; i++) //按照连接数建立读写对象
            {
                userToken               = new AsyncSocketUserToken(ReceiveBufferSize);
                userToken.AsyncSocket   = this;
                userToken.PacketProcess = oPacketProcess;
                userToken.ReceiveEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed);
                userToken.SendEventArgs.Completed    += new EventHandler <SocketAsyncEventArgs>(IO_Completed);
                AsyncSocketUserTokenPool.Push(userToken);
            }
        }