Skip to content

使用 net.Conn 调用Write时,frg 分片没有正常工作 #299

Description

@wfireleaves

kcp.go 中的Send方法,通过count处理frg

if len(buffer) <= int(kcp.mss) {
	count = 1
} else {
	count = (len(buffer) + int(kcp.mss) - 1) / int(kcp.mss)
}

但是在 sess.go 的 WriteBuffers 中,进行了mss的比较和分片,然后才调用了 Send,保证每次Send的都不超过 mss

for _, b := range v {
	n += len(b)
	// handle each slice for packet splitting
	for {
		if len(b) <= int(s.kcp.mss) {
			s.kcp.Send(b)
			break
		} else {
			s.kcp.Send(b[:s.kcp.mss])
			b = b[s.kcp.mss:]
		}
	}
}

因此在直接写入一个超过mss的包期望分片的时候,它不会按照预期工作,以至客户端在读取的时候出现错误。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions