public void Discard() { if (_isConstant) { return; } _result = default; IsCompleted = false; if (_stateMachine != null) { SmPool.Recycle(_stateMachine); } _stateMachine = null; Pool.Recycle(this); }
public SessionIOCP() { //TODO: optimize SocketAsyncEventArgs distribution m_hSendOps = new ConcurrentPool<SocketAsyncEventArgs>(); m_hRecvOps = new ConcurrentPool<SocketAsyncEventArgs>(); for (int i = 0; i < 10; i++) { SocketAsyncEventArgs hSendOp = new SocketAsyncEventArgs(); hSendOp.Completed += OnSendCompleted; hSendOp.SetBuffer(new byte[BufferSize], 0, BufferSize); m_hSendOps.Recycle(hSendOp); SocketAsyncEventArgs hRecvOp = new SocketAsyncEventArgs(); hRecvOp.Completed += OnRecvCompleted; hRecvOp.SetBuffer(new byte[BufferSize], 0, BufferSize); m_hRecvOps.Recycle(hRecvOp); } m_hRecvBuffer = new byte[BufferSize]; m_hMs = new MemoryStream(m_hRecvBuffer); m_hReader = new BinaryReader(m_hMs); }