在使用boost :: asio时,我遇到了一个有趣的时刻。问题是我想进行语音聊天并使用OpenAL,我将捕获的数据保存在A字节中:
ALubyte* data; // data has the captured data now
int data_size;
所以我发送数据将其转换为char *
boost::asio::streambuf m_buf;
std::ostream out(&m_buf);
out << data_size << ';'; // the simbol ';' is used to separate data from each other
out.write((char*)data, data_size);
out << 'q'; // the simbol 'q' is used for a client side to understand that
//this is the end of the stream
// as a client where the 'out' stream is sent to,
//uses boost::async_read_until --> ooops
boost::asio::async_write(client_sock, m_buf, [](){});
正如您可能已经猜到的那样,问题在于boost :: asio :: async_read_until
//in a client side
boost::asio::streambuf client_buf;
std::istream in(&client_buf);
boost::asio::async_read_until(m_sock, client_buf, 'q', [](){});//---> oooops,
// this boost::asio::async_read_until
//function reads until the first 'q' simbol which 'data' might
//have a lot of 'q' simbol as the captured data is stored as
// a char type
//so the function does not read the whole captured data.
伙计们我知道这是我自己选择这个功能的大错误,但我现在不能改变它,因为代码有点大,所以你有一些想法在这种情况下做什么,以便我可以阅读整个捕获数据,或者你认为没有改变boost :: asio :: async_read_until函数就没有出路?任何想法都非常感谢!!!
而不是simbol'q',更好的选择是添加更多的符号如“cpp”,在这种情况下,将捕获的数据保存在char类型中的数据可能没有相同的签名,'q'符号可能很多在数据中,但使用“cpp”...等风险将少于一个'q'辛博尔,这意味着添加的符号越多风险越小!