mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-26 13:57:47 +08:00
fix
This commit is contained in:
@@ -105,8 +105,23 @@ func (m *Me) listen() (conn *net.UDPConn, err error) {
|
||||
|
||||
// Read 接收所有发送给本机的报文
|
||||
// 需要开启 nopipe
|
||||
func (m *Me) Read() *head.Packet {
|
||||
return <-m.pipe
|
||||
func (m *Me) Read(p []byte) (n int, err error) {
|
||||
if len(m.readptr) > 0 {
|
||||
n = copy(p, m.readptr)
|
||||
m.readptr = m.readptr[n:]
|
||||
if n == len(p) {
|
||||
return
|
||||
}
|
||||
p = p[n:]
|
||||
}
|
||||
data := (<-m.pipe).Data
|
||||
c := copy(p, data)
|
||||
n += c
|
||||
if c == len(data) {
|
||||
return
|
||||
}
|
||||
m.readptr = data[c:]
|
||||
return
|
||||
}
|
||||
|
||||
// 从 conn 读取 sz 字节数据
|
||||
|
||||
@@ -39,6 +39,7 @@ type Me struct {
|
||||
clock map[*head.Packet]uint8
|
||||
// 本机上层配置
|
||||
srcport, dstport, mtu uint16
|
||||
readptr []byte
|
||||
}
|
||||
|
||||
// NewMe 设置本机参数
|
||||
|
||||
Reference in New Issue
Block a user