Tom*_*ica 1 c++ sockets boost boost-asio
我只是创建一个非常简单的C++类,它为我提供了几个方法,如connect()和read(),而不是公开所有Boost.Asio的套接字调用.
现在,我正在尝试找出如何创建一个只读取所需字节数的方法:
SocketClient::read(int bytes, char* data); //reads desired amount of bytes and puts them in data, size of data>bytes!
Run Code Online (Sandbox Code Playgroud)
不幸的是,我read_byte在Boost.Asio中找不到任何功能.我不想丢弃已收到但尚未读取的字节.
该读取功能似乎恰好提供你所需要的:
此函数用于从流中读取一定数量的字节数据.该调用将阻塞,直到满足下列条件之一为止:
Run Code Online (Sandbox Code Playgroud)- The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes. - An error occurred.
用法示例:
boost::asio::read(stream, boost::asio::buffer(data, size));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4402 次 |
| 最近记录: |