[英]Reading single byte with Asio::read
Is it possible to read a single byte via asio::read? 是否可以通过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. boost :: asio是在Windows重叠的I / O TCP Winsock实现之上实现的。 There's no way around buffers, etc. in such an implementation.
在这样的实现中,没有办法绕过缓冲区等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.