简体   繁体   中英

Reading single byte with Asio::read

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;

Thanks.

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.

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