gpt4 book ai didi

我可以在阻塞模式下在 send() 之后立即释放我的数据吗?

转载 作者:行者123 更新时间:2023-12-01 15:51:07 25 4
gpt4 key购买 nike

文档说发送:

When the message does not fit into the send buffer of the socket, send() normally blocks, unless the socket has been placed in non-block- ing I/O mode. In non-blocking mode it would return EAGAIN in this case. The select(2) call may be used to determine when it is possible to send more data.

我处于阻塞模式,按照以下方式做一些事情:

buf = malloc(size);

send (socket, buf, size);

free(buf)

假设 but 非常大,大于缓冲区一次可以容纳的大小(所以它需要进入缓冲区,可以说是两个 block )。无论如何,在我所处的阻塞模式下,发送后,我可以放心地确保数据已被完全复制或处理并因此可以删除吗?

最佳答案

在阻塞模式下,send 阻塞直到 I/O 完成,或者触发错误。您应该检查返回值,因为 send 操作不能保证发送的字节数与作为第三个参数传递的字节数相同。

只有当 send 返回一个等于发送缓冲区大小的值时,您才能确定整个 block 已被复制到内核内存中,或通过设备内存传递,或发送到目的地.

关于我可以在阻塞模式下在 send() 之后立即释放我的数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29442347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com