Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 提升ASIO异步读取直到不';使用ASIO ssl客户端示例编译_C++_Ssl_Asynchronous_Boost_Boost Asio - Fatal编程技术网

C++ 提升ASIO异步读取直到不';使用ASIO ssl客户端示例编译

C++ 提升ASIO异步读取直到不';使用ASIO ssl客户端示例编译,c++,ssl,asynchronous,boost,boost-asio,C++,Ssl,Asynchronous,Boost,Boost Asio,从开始,我想将async\u read()替换为async\u read\u until() 所以我查了一下,看到了如何调用async\u read\u until()。我看到它的名称如下: boost::asio::async_read_until(socket_, response_, "\r\n", boost::bind(&client::handle_read_status_line, this, boost::asio::placeho

从开始,我想将
async\u read()
替换为
async\u read\u until()

所以我查了一下,看到了如何调用
async\u read\u until()
。我看到它的名称如下:

      boost::asio::async_read_until(socket_, response_, "\r\n",
      boost::bind(&client::handle_read_status_line, this,
        boost::asio::placeholders::error));
因此,与SSL客户机示例相比,我看到的唯一区别是
response\uuu
是一个
boost::asio::streambuf
。因此,我以相同的方式在我的类主体中创建了该对象,然后在SSL客户端示例中,我替换了回调函数:

  boost::asio::async_read(socket_,
      boost::asio::buffer(reply_, bytes_transferred),
      boost::bind(&SSLClient::handle_read, this,
        boost::asio::placeholders::error,
        boost::asio::placeholders::bytes_transferred));
使用其他功能,并删除传输的
字节
部分。它变成了:

    boost::asio::async_read_until(socket_, response_, "\r\n",
        boost::bind(&SSLClient::handle_read, this,
        boost::asio::placeholders::error));
但是。。。这不能编译。它给了我这些错误:

In file included from /usr/include/boost/bind.hpp:22:0,
                 from SSLClient.h:5,
                 from main.cpp:14:
/usr/include/boost/bind/bind.hpp: In instantiation of 'struct boost::_bi::result_traits<boost::_bi::unspecified, void (SSLClient::*)(const boost::system::error_code&, long unsigned int)>':
/usr/include/boost/bind/bind_template.hpp:15:48:   required from 'class boost::_bi::bind_t<boost::_bi::unspecified, void (SSLClient::*)(const boost::system::error_code&, long unsigned int), boost::_bi::list2<boost::_bi::value<SSLClient*>, boost::arg<1> (*)()> >'
SSLClient.h:99:51:   required from here
/usr/include/boost/bind/bind.hpp:69:37: error: 'void (SSLClient::*)(const boost::system::error_code&, long unsigned int)' is not a class, struct, or union type
     typedef typename F::result_type type;
                                     ^
In file included from main.cpp:14:0:
SSLClient.h:87:70: warning: unused parameter 'bytes_transferred' [-Wunused-parameter]
     void handle_write(const boost::system::error_code& error, size_t bytes_transferred)
                                                                      ^
In file included from /usr/include/boost/asio/impl/io_service.hpp:18:0,
                 from /usr/include/boost/asio/io_service.hpp:767,
                 from /usr/include/boost/asio/basic_io_object.hpp:19,
                 from /usr/include/boost/asio/basic_socket.hpp:20,
                 from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
                 from /usr/include/boost/asio.hpp:21,
                 from SSLClient.h:6,
                 from main.cpp:14:
/usr/include/boost/asio/impl/read_until.hpp: In instantiation of 'typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, const string&, ReadHandler&&) [with AsyncReadStream = boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp> >; Allocator = std::allocator<char>; ReadHandler = boost::_bi::bind_t<boost::_bi::unspecified, void (SSLClient::*)(const boost::system::error_code&, long unsigned int), boost::_bi::list2<boost::_bi::value<SSLClient*>, boost::arg<1> (*)()> >; typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type = void; std::string = std::basic_string<char>]':
SSLClient.h:99:52:   required from here
/usr/include/boost/asio/impl/read_until.hpp:707:3: error: static assertion failed: ReadHandler type requirements not met
   BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
   ^
/usr/include/boost/asio/impl/write.hpp:615:3: error: no match for call to '(boost::_bi::bind_t<boost::_bi::unspecified, void (SSLClient::*)(const boost::system::error_code&, long unsigned int), boost::_bi::list2<boost::_bi::value<SSLClient*>, boost::arg<1> (*)()> >) (const boost::system::error_code&, const long unsigned int&)'
   BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
   ^
Makefile:472: recipe for target 'main.o' failed
make: *** [main.o] Error 1
13:14:05: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project GNOMEClientCmd (kit: Qt 5.4.1)
When executing step "Make"
13:14:05: Elapsed time: 00:04.
在/usr/include/boost/bind.hpp:22:0中包含的文件中,
来自SSL客户。h:5,
来自main.cpp:14:
/usr/include/boost/bind/bind.hpp:在“struct boost::_bi::result_traits”的实例化中:
/usr/include/boost/bind/bind_template.hpp:15:48:来自“类boost::_bi::bind_t”的必填项
SSLClient.h:99:51:从这里开始需要
/usr/include/boost/bind/bind.hpp:69:37:错误:“void(SSLClient::*)(const boost::system::error_code&,long unsigned int)”不是类、结构或联合类型
typedef typename F::result_type type;
^
在main.cpp中包含的文件中:14:0:
SSLClient.h:87:70:警告:未使用的参数“已传输字节”[-Wunused参数]
无效句柄\u写入(常量boost::系统::错误\u代码和错误,大小\u t字节\u传输)
^
在/usr/include/boost/asio/impl/io_service.hpp:18:0中包含的文件中,
从/usr/include/boost/asio/io_service.hpp:767,
从/usr/include/boost/asio/basic\u io\u object.hpp:19,
从/usr/include/boost/asio/basic_socket.hpp:20,
从/usr/include/boost/asio/basic_datagram_socket.hpp:20,
从/usr/include/boost/asio.hpp:21,
来自SSL客户。h:6,
来自main.cpp:14:
/usr/include/boost/asio/impl/read_until.hpp:在“typename boost::asio::async_result::type boost::asio::async_read_until”的实例化中(AsyncReadStream&,boost::asio::basic_streambuf&,const string&,ReadHandler&)[with AsyncReadStream=boost::asio::ssl::stream;分配器=std::分配器;ReadHandler=boost::\u bi::bind\u t;typename boost::asio::async\u result::type=void;std::string=std::basic\u string]:
SSLClient.h:99:52:从这里开始需要
/usr/include/boost/asio/impl/read_until.hpp:707:3:错误:静态断言失败:未满足ReadHandler类型要求
BOOST\u ASIO\u READ\u HANDLER\u CHECK(ReadHandler,HANDLER)类型\u CHECK;
^
/usr/include/boost/asio/impl/write.hpp:615:3:错误:调用“(boost::_bi::bind_t)(const boost::system::error_code&,const long unsigned int&)不匹配
BOOST\u ASIO\u WRITE\u HANDLER\u CHECK(WriteHandler,HANDLER)类型\u CHECK;
^
Makefile:472:目标“main.o”的配方失败
make:**[main.o]错误1
13:14:05:进程“/usr/bin/make”已退出,代码为2。
生成/部署项目GNOMEClientCmd时出错(工具包:Qt 5.4.1)
执行步骤“Make”时
13:14:05:运行时间:00:04。
要得到所有这些错误,我所要做的就是从
async\u read
切换到
async\u read\u,直到
。如果我回到
async\u read
,它编译得很好。我做错了什么

如果您需要任何其他信息,请询问。谢谢

我做错了什么

你忽略了文档

文档将告诉您,
async\u read-until
以streambufñ为例,仍然需要传输的
bytes\u
占位符



我刚刚注意到你在散文中描述了这一点;显示相关代码效果更好。因此,你让我注意到,我忘记删除回调函数中传输的
字节
占位符。我删除了它并编译了它。老实说,这是回调函数中最糟糕的事情。它们的调试这是一场噩梦,非常不清楚。没有明确的迹象表明问题是什么,人们只能猜测和想象…我希望有更好的方法调试回调函数。谢谢。好吧。老实说,我不值得你大骂。如果你有一个有能力的编译器,就使用lambdas。这里甚至不是Asio堆栈(它确实有回调概念断言)这只是绑定呕吐。你不需要用lambda绑定。帮助你的编译器帮助你。抱歉,伙计,这不是一个咆哮。我非常感谢你的帮助。我只是抱怨这是多么烦人,因为这是一个微不足道的问题,我无法注意到,因为编译器的大量报告称错误远离真实问题。这与你无关:-谢谢拉姆达斯的建议,我会考虑的。