示例#1
0
 /// <summary>
 /// 入
 /// </summary>
 /// <param name="saea"></param>
 public void Push(IOCPToken saea)
 {
     if (saea != null)
     {
         lock (saeaStack)
         {
             saeaStack.Push(saea);
         }
     }
 }
示例#2
0
 /// <summary>
 /// 关闭已接受客户端连接的socket
 /// </summary>
 /// <param name="token"></param>
 private void Close(IOCPToken token)
 {
     try
     {
         Socket s = token.Client;
         if (s != null)
         {
             try
             {
                 s.Shutdown(SocketShutdown.Both);
             }
             catch (Exception) { }
             finally
             {
                 s.Close();
             }
             //去除原子操作
             Interlocked.Decrement(ref clientCount);
             //释放句柄
             token.Client = null;
             //释放信号量
             sem.Release();
             //入SocketAsyncEventArgs对象池
             saeap.Push(token);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 /// <summary>
 /// 初始化buffer管理、SocketAsyncEventArgs操作完成事件、SocketAsyncEventArgs对象池管理
 /// </summary>
 public void Init()
 {
     bm.InitBuffer();
     IOCPToken token;
     for (int i = 0; i < ClientMaxCount; i++)
     {
         token = new IOCPToken();
         token.ReceiveSAEA.Completed += new EventHandler<SocketAsyncEventArgs>(SAEACompleted);
         token.SendSAEA.Completed += new EventHandler<SocketAsyncEventArgs>(SAEACompleted);
         token.Client = null;
         bm.SetBuffer(token.ReceiveSAEA);
         bm.SetBuffer(token.SendSAEA);
         saeap.Push(token);
     }
 }
示例#4
0
 public SocketEventHandle(IOCPTCPAid iocpa,IOCPToken token)
 {
     this.iocpa = iocpa;
     this.token = token;
 }