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 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法