[英]Protobuf and Non-blocking message send/recv
I am developing my message passing interface using protobuf
and non-blocking libevent
socket libraries. 我正在使用
protobuf
和非阻塞libevent
套接字库开发消息传递接口。 Because of the non-blocking properties, the read callback by libevent
might be invoked at some points where the messages are not complete (eg, every 4096 bytes received). 由于具有非阻塞属性,
libevent
的读取回调可能在消息未完成的某些点(例如,每接收到4096个字节)被调用。 This means I have to write another wrapper/header indicating the size of each message so I can parse the message back to the protobuf
object correctly. 这意味着我必须编写另一个表示每个消息大小的包装器/标头,以便可以将消息正确地解析回
protobuf
对象。 Are there better solutions for this? 有更好的解决方案吗? Or does
protobuf
provide an API to handle this situation? 还是
protobuf
提供API来处理这种情况?
No, there is no better solution. 不,没有更好的解决方案。 In fact, even when using blocking I/O, you need to write a header indicating the size, because Protobufs are not self-delimiting (by default the protobuf parser will always read until EOF!).
实际上,即使使用阻塞I / O,您也需要写一个标头来指示大小,因为Protobuf并不是自定界的(默认情况下,protobuf解析器将始终读取直到EOF!)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.