// create a new kcp control object, 'conv' must equal in two endpoint // from the same connection. public KCP(UInt32 conv_, Action <byte[], int> output_) { conv = conv_; snd_wnd = IKCP_WND_SND; rcv_wnd = IKCP_WND_RCV; rmt_wnd = IKCP_WND_RCV; mtu = IKCP_MTU_DEF; mss = mtu - IKCP_OVERHEAD; rx_rto = IKCP_RTO_DEF; rx_minrto = IKCP_RTO_MIN; interval = IKCP_INTERVAL; ts_flush = IKCP_INTERVAL; ssthresh = IKCP_THRESH_INIT; dead_link = IKCP_DEADLINK; buffer = new byte[(mtu + IKCP_OVERHEAD) * 3]; output = output_; //创建报文包对象池 m_oSegmentPool = new ThreadQueue <Segment>(); m_oSegmentPool.Create(); //内存池 m_oMemPool = new MemPool(); m_oMemPool.Create(); // }
//创建 public bool Create() { m_oMemPool = new MemPool(); m_oMemPool.Create(); m_oDataQueue = new ThreadQueue <ByteData>(); m_oDataQueue.Create(); m_oRecycleQueue = new ThreadQueue <ByteData>(); m_oRecycleQueue.Create(); return(true); }
//释放 public void Release() { if (null != m_oSegmentPool) { m_oSegmentPool.Release(); m_oSegmentPool = null; } if (null != m_oMemPool) { m_oMemPool.Release(); m_oMemPool = null; } }
//销毁 public void Release() { if (null != m_oMemPool) { m_oMemPool.Release(); m_oMemPool = null; } if (null != m_oDataQueue) { m_oDataQueue.Release(); m_oDataQueue = null; } if (null != m_oRecycleQueue) { m_oRecycleQueue.Release(); m_oRecycleQueue = null; } }