doubu5154 2016-01-15 01:44
浏览 35

WSARecv不会停止阅读

So basically, I use WSARecv with this function from my client :

type Conn struct {
    sd s.Handle
    sa s.SockaddrInet4
}

func (c *Conn) Read(b []byte) (int, error) {
    dataBuf := s.WSABuf{Len: uint32(len(b)), Buf: &b[0]}
    flags := uint32(0)
    qty := uint32(0)
    err := s.WSARecv(c.sd, &dataBuf, 1, &qty, &flags, nil, nil)
    return int(qty), err
}

Meanwhile the server is sending multiple packets (first one is 8 bytes, then they're all under 1000 bytes).

What happens is that WSARecv doesn't stop to read when the buffer b is full. So I got an hard answer when It's taking too much memory :

Exception 0xc0000005 0x8 0xc08203195f 0xc08203195f PC=0xc08203195f syscall.Syscall9(0x7ff86cafe230, 0x7, 0x1f8, 0xc08200b5d0, 0x1, 0xc08200b5f0, 0xc08200b5e0, 0x0, 0x0, 0x0, ...) (dozen of lines like that)

And my program crash of course.

I wondered if my problem was about the way I use WSARecv or if I've to send back an aknowledgment every time I receive a packet.

NB : my server is under linux (and client under windows ofc).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作