V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
qemu32
V2EX  ›  Linux

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

  •  
  •   qemu32 · 2022-09-17 09:31:47 +08:00 · 1175 次点击
    这是一个创建于 559 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2022-09-17 09:57:00 +08:00
    heiher
        1
    heiher  
       2022-09-17 09:51:28 +08:00
    链接的示例是 Blocking I/O 吧,Non-blocking I/O 用 vector I/O 方式太麻烦了
    qemu32
        2
    qemu32  
    OP
       2022-09-17 09:54:08 +08:00
    @heiher 感谢回复,我用的是 Blocking I/O
    qemu32
        3
    qemu32  
    OP
       2022-09-17 09:57:00 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5906 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 02:10 · PVG 10:10 · LAX 19:10 · JFK 22:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.