V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
qemu32
V2EX  ›  Linux

Linux c 编程问题请教,使用 readv/writev 读写 iovec 数组,如何循环读取或写入直到全部字节传输完毕?

  •  
  •   qemu32 · Sep 17, 2022 · 2181 views
    This topic created in 1323 days ago, the information mentioned may be changed or developed.

    https://www.oreilly.com/library/view/linux-system-programming/0596009585/ch04.html

    这个教程的示例代码没有考虑 readv/writev 没有一次性读写 iovec 数组全部内容的情况,因为 readv/writev 和 read/write 一样可能调用一次只读写了一部分数据,read/write 可以使用一个简单的 while 循环来保证读取或写入直到全部完成,readv/writev 的情况我不知道代码该怎么写,比如如何计算整个 iovec 数组所有元素加起来的总大以及 while 循环该怎么写。

    3 replies    2022-09-17 09:57:00 +08:00
    heiher
        1
    heiher  
       Sep 17, 2022
    链接的示例是 Blocking I/O 吧,Non-blocking I/O 用 vector I/O 方式太麻烦了
    qemu32
        2
    qemu32  
    OP
       Sep 17, 2022
    @heiher 感谢回复,我用的是 Blocking I/O
    qemu32
        3
    qemu32  
    OP
       Sep 17, 2022
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2545 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 12:56 · PVG 20:56 · LAX 05:56 · JFK 08:56
    ♥ Do have faith in what you're doing.