/// <summary> /// 释放一个SocketAsyncEventArgs /// </summary> /// <param name="socketEvent">SocketAsyncEventArgs</param> public void FreeSocketEvent(SocketAsyncEventArgs socketEvent) { MySocketAsyncEventArgs se = socketEvent as MySocketAsyncEventArgs; if (se != null) { try { socketEvent.SetBuffer(0, 0); SocketEventStack.Push(se); } catch (Exception e) { LogLib.Log.WriteLog(e.TargetSite + "->" + e.Message, LogLib.LogType.ERROR); } } }
/// <summary> /// 获取一个空闲的SocketAsyncEventArgs /// </summary> /// <returns>SocketAsyncEventArgs</returns> public MySocketAsyncEventArgs GetSocketEvent() { if (SocketEventStack.Count > 0) { return(SocketEventStack.Pop()); } else { int value = Interlocked.Increment(ref MaxConnection); MySocketAsyncEventArgs eventArgs = new MySocketAsyncEventArgs { CurrentIndex = value }; return(eventArgs); } }