开发者

Reading single byte with Asio::read

开发者 https://www.devze.com 2023-01-09 09:42 出处:网络
Is it possible to read a single byte via asio::read? I\'m getting a single byte response and it seems wasteful to use the current buffering code:

Is it possible to read a single byte via asio::read?

I'm getting a single byte response and it seems wasteful to use the current buffering code:

        //Read the 1 byte reply
        char buffer[1];
        size_t bytesRead = asio::read(s, asio::buffer(buffer, 1));
        if(bytesRead < 1) return false;

Tha开发者_Python百科nks.


No, passing a buffer of a single byte is the only way.

Also it isn't wasteful. What is it that you're concerned about wasting?


boost::asio is implemented on top of Windows' overlapped I/O TCP Winsock implementation. There's no way around buffers, etc. in such an implementation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号