知识卡片
异步读取更新缓冲游标
读接口的适配需要对齐“已分配”“已初始化”和“已填充”三个状态。下层返回成功的字节数才能推进填充区。Pending 要继续借助 Context 的唤醒机制。误把容量当已填充长度,会把未读取的数据交给解析器。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 4. Integrating Networking into Our Own Async Runtime 读取适配与 ReadBuf · 查看原书依据
The map_ok also references itself, which is the result from poll_read. If the Poll result is Ready but with an error, Ready with the error is returned. If the Poll result is Pending, Pending is returned. We pass the context into poll_read so a waker is used if we have a Pending result. If we have a Ready with an Ok result, the closure is
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第04章《Chapter 4. Integrating Networking into Our Own Async Runtime》,读取适配与 ReadBuf(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch04.html#id26)
- 结论依据:原书通过 map_ok 只在 Ready Ok 时更新实际填充的字节数。
- 原始内容:The map_ok also references itself, which is the result from poll_read. If the Poll result is Ready but with an error, Ready with the error is returned. If the Poll result is Pending, Pending is returned. We pass the context into poll_read so a waker is used if we have a Pending result. If we have a Ready with an Ok result, the closure is