Boost read_also()函数不能与Boost::array一起工作,不能使用std::array
Boost read_also() function not working with boost::array, cannot use std::array
我有这个代码打开一个boost套接字,写一个命令,通过套接字发送命令,并获得结果:
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <array>
#include <string>
#define MAXSIZE 1000000
//...
void MyClass::processCommand(std::string command)
{
boost::asio::io_service io;
boost::asio::ip::tcp::socket socket(io);
boost::asio::ip::tcp::endpoint e(boost::asio::ip::address::from_string("127.0.0.1"), 60151); //Info for the connection I need to make...
this->socket.open(boost::asio::ip::tcp::v4());
this->socket.connect(e);
this->socket.write_some(boost::asio::buffer(command, command.size());
this->socket.send(boost::asio::buffer(command, command.size());
boost::array<char, MAXSIZE> buffer;
this->socket.read_some(boost::asio::buffer(buffer));
}
这段代码编译并运行,但是在调用read_some()
的行上卡住了,我不知道为什么。如果谁有什么解决办法,我将不胜感激。
您写了command.size()
字节
然后请求读取MAXSIZE
字节。
如果command.size()
<MAXSIZE
,为什么它不等待更多的字节从管道下来呢?>
先写数据包的大小,再写数据包的字节数。
在读取端,首先读取数据包的大小,然后读取数据包的多少字节。
read_some
可以自由地读取比您请求的少的字节,但是我没有看到任何文档说它必须在读取您请求的那么多字节之前返回。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的for循环不能正确获取argv
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 为什么模板类中的对象不能返回值
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- 为什么不能用两层列表初始值设定项初始化 2D std::array?
- 为什么我不能将 C 样式数组复制到 std::array?
- 为什么我们不能将 int array[] 传递给 hoo(int* &p)?
- 为什么不能简单地初始化(用大括号)2D std::array?
- 不能直接分配元素 std::array,它说没有运算符"="匹配
- 我们不能从initializer_list创建一个 std::array,但我们可以使用带有可变参数的辅助函数来创建它
- 为什么 std::stoi 和 std::array 不能使用 g++ c++11 编译
- 为什么不能使用 auto 作为模板类型参数(例如 std::array<auto, 5>)?
- Boost read_also()函数不能与Boost::array一起工作,不能使用std::array
- 为什么我不能像这样淡化 std::array?
- 为什么我们不能将 &数组传递给 &array[0] 可能的功能