Esempio n. 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="id">唯一ID</param>
 /// <param name="receiveBuffer">接收缓冲区</param>
 /// <param name="sendBuffer">发送缓冲区</param>
 /// <param name="socket">连接的Socket</param>
 /// <param name="process"></param>
 public UserSession(int id, UserBuffer buffer, Socket socket, IBufferProcessor process)
     : base(id, buffer.ReceiveBuffer, buffer.SendBuffer, process, buffer.SendPool)
 {
     m_socket = socket;
     Buffer = buffer;
     m_address = ((System.Net.IPEndPoint)(socket.RemoteEndPoint)).Address;
     Created = DateTime.UtcNow;
 }
Esempio n. 2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="maxClients">允许的最大连接数</param>
 /// <param name="receiveBufferSize">每个连接接收数据缓存的大小</param>
 /// <param name="sendBufferSize">每个连发送收数据缓存的大小</param>
 /// <param name="sendQueueSize">等待发送数据的最大业务包</param>
 public SessionFactory(int maxClients, int receiveBufferSize, int sendBufferSize, int sendQueueSize, IBufferProcessor commandReader)
 {
     m_receiveBufferSize = receiveBufferSize;
     m_sendBufferSize = sendBufferSize;
     m_bufferPool = new System.Collections.Concurrent.ConcurrentQueue<UserBuffer>();
     m_receivebuffer = new byte[maxClients * receiveBufferSize];
     m_sendbuffer = new byte[maxClients * sendBufferSize];
     m_process = commandReader;
     for (int i = 0; i < maxClients; i++)
     {
         var receivebuffer = new Sinan.Collections.BytesSegment(m_receivebuffer, m_receiveBufferSize * i, m_receiveBufferSize);
         var sendbuffer = new Sinan.Collections.BytesSegment(m_sendbuffer, m_sendBufferSize * i, m_sendBufferSize);
         UserBuffer helper = new UserBuffer(i, this, receivebuffer, sendbuffer, sendQueueSize);
         m_bufferPool.Enqueue(helper);
     }
 }
Esempio n. 3
0
 internal void ReoverySession(UserBuffer helper, ISession token)
 {
     UserSession session;
     if (m_sessions.TryRemove(token.ConnectID, out session))
     {
         m_bufferPool.Enqueue(helper);
     }
 }
Esempio n. 4
0
 public override void Close()
 {
     UserBuffer buffer = null;
     PlayerBusiness player = null;
     lock (m_locker)
     {
         if (Buffer == null)
         {
             return;
         }
         player = m_player;
         buffer = Buffer;
         Buffer = null;
     }
     try
     {
         //已登录用户断开连接
         if (m_userID != null)
         {
             UserExit();
             UserNote note = new UserNote(this, ClientCommand.UserDisconnected, new object[] { this });
             Notifier.Instance.Publish(note);
         }
     }
     finally
     {
         base.Close();
         buffer.Free(this);
         m_player = null;
         if (player != null)
         {
             player.DisConnection(this);
         }
     }
 }