- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
上下文:我正致力于在与 Boost ASIO 集成的 RDMA 包装器库之上实现一个简单的流适配器。
我遇到的问题是,客户端代码调用的 boost::asio::async_read
聚合器挂起,即使流已返回足够的数据来填充缓冲区,如果内部接收缓冲区中不再有未决数据。调试似乎表明它正在使用大小为 0 的单个缓冲区调用我的流适配器的 async_read_some
方法。
我发现的文档似乎在该操作是否应立即完成方面存在冲突。一方面,the AsyncReadStream concept specification说:
If the total size of all buffers in the sequence
mb
is 0, the asynchronous read operation shall complete immediately and pass 0 as the argument to the handler that specifies the number of bytes read.
另一方面,the overview of boost::asio::null_buffers
说:
A
null_buffers
operation doesn't return until the I/O object is "ready" to perform the operation.
(事实上,在其他地方,我依靠它来注册处理程序,以便在 rdma_cm 和 ibverbs 完成 channel FD 指示可用事件时调用。)但是查看 null_buffers
的实现,它看起来它只是一个不包含缓冲区的静态对象,因此这似乎满足所有缓冲区的总大小为 0 的序列条件。
所以,我对我的 async_read_some
方法应该如何处理尝试读取 0 字节的情况感到困惑。作为一个疯狂的猜测,也许它应该是这样的:在像 null_buffers
这样的真正空序列上它应该只在接收缓冲区中有可用数据时完成,而如果它有一个非空序列缓冲区的长度等于 0 那么无论接收缓冲区的状态如何,它都应该立即完成?
最佳答案
注意 null_buffers
自 Boost 1.66.0 以来已被弃用:"(Deprecated: Use the socket/descriptor wait() and async_wait() member functions.)"
As a wild guess, maybe it should be something like: on a truly empty sequence like null_buffers it should complete only when there's data available in the receive buffer, while if it has a non-empty sequence with total length of the buffers equal to 0 then it should complete immediately regardless of the state of the receive buffer?
没有。 null_buffers
不是“空缓冲区”或“零长度缓冲区”。它是“无缓冲区”,向 ASIO 例程发出信号,表明没有缓冲区(因此大小在逻辑上不能被认为是零)。
所有与缓冲区大小有关的完成说明都是无关紧要的,因为不存在缓冲区。相关文档是 Reactor Style Operations .
您说得对:传递 null_buffers
表示您希望将 react 器式操作编织到 asio 事件子系统中(意思是,您可以异步等待套接字准备好进行读/写,然后执行实际的 IO,例如将底层套接字句柄传递给本身不支持异步 IO 的第三方 API。
关于c++ - `stream.async_read_some(null_buffers,handler)` 是否应该立即完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46611466/
我正在尝试实现具有以下签名的方法: public static Pair, Stream> flatten(Iterator, Stream>> iterator); 该方法的目标是将每种流类型展平
我有两个流从两个不同的 api 获取。 Stream get monthOutStream => monthOutController.stream; Stream get resultOutStre
Stream.of(int[])返回 Stream ,而 Stream.of(String[])返回 Stream . 为什么这两种方法的行为不同?两者都应该返回 Stream和 Stream或 St
我正在使用 rxdart在 dart 中处理流的包。我被困在处理一个特殊的问题上。 请看一下这个虚拟代码: final userId = BehaviorSubject(); Stream getSt
我到处都找遍了,还是没弄明白。我知道你可以用流建立两个关联: 用于支持数据存储的包装器意味着作为消费者和供应商之间的抽象层 数据随着时间的推移变得可用,而不是一次全部 SIMD 代表单指令,多数据;在
考虑下面的代码: List l=new ArrayList<>(); l.add(23);l.add(45);l.add(90); Stream str=l.stream
我有一个大型主干/requirejs 应用程序,我想迁移到 webpack,最新的“webpack”:“^4.27.1”,但我遇到了一个我无法解决的错误。 我一直在阅读 https://webpack
我正在使用 xmpp 开发聊天应用程序,根据我们的要求,我们有三台服务器 Apache Tomcat 7、ejabbered 2.1.11 和 mysql 5.5, to run xmppbot on
我知道如何使用 Java 库,并且我可以编写一些循环来执行我需要的操作,但问题更多,为什么 scala.collection.JavaConverters 中没有任何内容或scala.collecti
我正在尝试创建一个单一的衬里,它应该计算一个非常长的文本文件中的唯一单词。独特的词例如:márya fëdorovna scarlet-liveried,...所以基本上都是非英语词。 我的问题是我的
如果我有以下情况: StreamWriter MySW = null; try { Stream MyStream = new FileStream("asdf.txt"); MySW =
有人可以帮我将以下语句转换为 Java8: 我有一个像这样的 HashMap : private Map, List>> someMap; 我想在java8中转换以下逻辑: private Strin
有人可以帮我将以下语句转换为 Java8: 我有一个像这样的 HashMap : private Map, List>> someMap; 我想在java8中转换以下逻辑: private Strin
考虑两种测试方法parallel()和sequential(): @Test public void parallel() throws Exception { System.ou
我是 NodeJS 的新手,我基本上想做的是通过 HTTP 将 .pdf 上传到我的服务器。我正在使用 POST rquest 来处理 Content-Type multipart/form-data
哪个更好:MemoryStream.WriteTo(Stream destinationStream) 或 Stream.CopyTo(Stream destinationStream)?? 我正在谈
给定一个 Stream,我想创建一个新的 Stream,其中的元素在它们之间有时间延迟。 我尝试使用 tokio_core::reactor::Timeout 和 Stream 的 and_then
我是 Kafka Streams 和 Spring Cloud Stream 的新手,但在将集成相关代码移动到属性文件方面已经阅读了有关它的好东西,因此开发人员可以主要专注于事物的业务逻辑方面。 这里
源代码看起来非常相似:pump , pipe .为什么我要使用一个而不是另一个?一个只是另一个的更好版本吗? 最佳答案 Stream.pipe 现在显然是自 0.3.x 以来的首选方法,因此尽可能尝试
我正在寻找是否有更好的方法来解决我不得不使用这些签名的困境(注意:由于 Spock 测试,T[][] 是必需的,我提供 T[][] 作为数据提供商) 我的方法签名是: public T[][] cr
我是一名优秀的程序员,十分优秀!