private void WriteRecv(IBufferWriter <byte> writer, Segment seg) { var curCount = (int)seg.len; var target = writer.GetSpan(curCount); seg.data.CopyTo(target); SegmentManager.Free(seg); writer.Advance(curCount); }
/// <summary> /// 这个函数不检查任何参数 /// </summary> /// <param name="buffer"></param> /// <returns></returns> int UncheckRecv(Span <byte> buffer) { var recover = false; if (rcv_queue.Count >= rcv_wnd) { recover = true; } #region merge fragment. /// merge fragment. var recvLength = 0; lock (rcv_queueLock) { var count = 0; foreach (var seg in rcv_queue) { seg.data.CopyTo(buffer.Slice(recvLength)); recvLength += (int)seg.len; count++; int frg = seg.frg; SegmentManager.Free(seg); if (frg == 0) { break; } } if (count > 0) { rcv_queue.RemoveRange(0, count); } } #endregion Move_Rcv_buf_2_Rcv_queue(); #region fast recover /// fast recover if (rcv_queue.Count < rcv_wnd && recover) { // ready to send back IKCP_CMD_WINS in ikcp_flush // tell remote my window size probe |= IKCP_ASK_TELL; } #endregion return(recvLength); }