知识卡片
发送重试必须保留偏移
在非阻塞连接上,完全写入可能需要多次系统调用。如果已经写了头部或部分数据,重试整个数组会重复字节。每次成功后更新发送偏移,WouldBlock 时保存状态并等待可写事件。参见 [[异步写入的三种承诺]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 10. Building an Async Server with No Dependencies 非阻塞写的短写问题 · 查看原书依据
The set_nonblocking function makes the stream return a result immediately from the write, recv, read, or send functions. If the I/O operation was successful, the result will be Ok. If the I/O operation returns an io::ErrorKind::WouldBlock error, the IO operation needs to be retried because the stream was blocking. We handle these I/O operation outcomes as follows:
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第10章《Chapter 10. Building an Async Server with No Dependencies》,非阻塞写的短写问题(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch10.html#id90)
- 结论依据:原书示例在 WouldBlock 后重新轮询,代码使用 write_all。
- 原始内容:The set_nonblocking function makes the stream return a result immediately from the write, recv, read, or send functions. If the I/O operation was successful, the result will be Ok. If the I/O operation returns an io::ErrorKind::WouldBlock error, the IO operation needs to be retried because the stream was blocking. We handle these I/O operation outcomes as follows: