Exemplo n.º 1
0
 public ITcpSession Pop()
 {
     ITcpSession session;
     if (!pool.TryDequeue(out session))
     {
         if(count < maxSessions)
         {
             Interlocked.Increment(ref count);
             session = new TcpSession(loger);
             session.ReceiveEventArgs.SetBuffer(new byte[bufferSize], 0, bufferSize);
             session.PacketProtocol = new TcpPacketProtocol(bufferSize,bufferPoolSize,loger);
         }
     }
     return session;
 }
Exemplo n.º 2
0
        public ITcpSession Pop()
        {
            ITcpSession session;
            if (!pool.TryPop(out session))
            {
                if(count <= maxSessions)
                {
                    Interlocked.Increment(ref count);
                    session = new TcpSession(loger);
                    session.PacketProtocol = new TcpPacketProtocol(bufferSize,bufferPoolSize,loger);
                    session.SendEventArgs.Completed += session.PacketProtocol.SendComplate;//数据发送完成事件

                    session.ReceiveEventArgs.SetBuffer(new byte[bufferSize], 0, bufferSize);
                    session.ReceiveEventArgs.Completed += session.PacketProtocol.ReceiveComplate;

                }
            }
            return session;
        }