Kcp
Kcp回调
kcp 发送方向输出
kcp 交出发送缓冲区控制权,缓冲区来自
数据的有效长度
不需要返回值
通过增加 avalidLength 能够在协议栈中有效的减少数据拷贝
外部提供缓冲区,可以在外部链接一个内存池
https://github.com/skywind3000/kcp/wiki/Network-Layer
外部buffer ----拆分拷贝----等待列表 -----移动----发送列表----拷贝----发送buffer---output
https://github.com/skywind3000/kcp/issues/118#issuecomment-338133930
create a new kcp control object, 'conv' must equal in two endpoint
from the same connection.
频道号
最大传输单元(Maximum Transmission Unit,MTU)
缓冲区最小大小
最大报文段长度
下一个等待接收消息ID
https://github.com/skywind3000/kcp/issues/53
按照 C版 设计,使用小端字节序
发送 ack 队列
发送等待队列
正在发送列表
正在等待触发接收回调函数消息列表
需要执行的操作 添加 遍历 删除
正在等待重组消息列表
需要执行的操作 添加 插入 遍历 删除
是否正在释放
释放不是严格线程安全的,尽量使用和Update相同的线程调用,
或者等待析构时自动释放。
如果外部能够提供缓冲区则使用外部缓冲区,否则new byte[]
user/upper level recv: returns size, returns below zero for EAGAIN
这个函数不检查任何参数
move available data from rcv_buf -> rcv_queue
check the size of next message in the recv queue
user/upper level send, returns below zero for error
update ack.
when you received a low level packet (eg. UDP packet), call it
flush pending data
update state (call it repeatedly, every 10ms-100ms), or you can ask
ikcp_check when to call it again (without ikcp_input/_send calling).
DateTime.UtcNow
Determine when should you invoke ikcp_update:
returns when you should invoke ikcp_update in millisec, if there
is no ikcp_input/_send calling. you can call ikcp_update in that
time, instead of call update repeatly.
Important to reduce unnacessary ikcp_update invoking. use it to
schedule ikcp_update (eg. implementing an epoll-like mechanism,
or optimize ikcp_update when handling massive kcp connections)
change MTU size, default is 1400
** 这个方法不是线程安全的。请在没有发送和接收时调用 。
fastest: ikcp_nodelay(kcp, 1, 20, 2, 1)
0:disable(default), 1:enable
internal update timer interval in millisec, default is 100ms
0:disable fast resend(default), 1:enable fast resend
0:normal congestion control(default), 1:disable congestion control
set maximum window size: sndwnd=32, rcvwnd=32 by default
get how many packet is waiting to be sent
调整了没存布局,直接拷贝块提升性能。
结构体保存内容只有一个指针,不用担心参数传递过程中的性能
https://github.com/skywind3000/kcp/issues/118#issuecomment-338133930
不要对没有初始化的KcpSegment(内部指针为0,所有属性都将指向位置区域) 进行任何赋值操作,可能导致内存损坏。
出于性能考虑,没有对此项进行安全检查。
使用完必须显示释放,否则内存泄漏
释放非托管内存
以下为本机使用的参数
offset = 0
offset = 4
offset = 8
offset = 12
以下为需要网络传输的参数
offset =
https://github.com/skywind3000/kcp/issues/134
offset = + 4
offset = + 5
offset = + 6
offset = + 8
SendNumber?
offset = + 12
offset = + 16
AppendDateSize
offset = + 20
https://github.com/skywind3000/kcp/issues/35#issuecomment-263770736
将片段中的要发送的数据拷贝到指定缓冲区