简体   繁体   中英

Protobuf and Non-blocking message send/recv

I am developing my message passing interface using protobuf and non-blocking libevent socket libraries. 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). 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. Are there better solutions for this? Or does protobuf provide an API to handle this situation?

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!).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM