- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下使用 boost::asio 的代码将无法编译:
#pragma once
#include <ctime>
#include <iostream>
#include <string>
#include <stdint.h>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/asio.hpp>
class Connection
: public boost::enable_shared_from_this<Connection>
{
public:
typedef boost::shared_ptr<Connection> pointer;
static pointer create(boost::asio::io_service& io_service){return pointer(new Connection(io_service));}
virtual ~Connection();
boost::asio::ip::tcp::socket& socket();
virtual void Send(uint8_t* buffer, int length);
void handler(const boost::system::error_code& error, std::size_t bytes_transferred );
private:
explicit Connection(boost::asio::io_service& io_service);
boost::asio::ip::tcp::socket socket_;
boost::asio::ip::tcp::endpoint remote_endpoint_;
};
------------------------------------------------------------------------------------------------
#include "Connection.h"
Connection::Connection(boost::asio::io_service& io_service)
: socket_(io_service)
{
}
Connection::~Connection()
{
//dtor
}
boost::asio::ip::tcp::socket& Connection::socket(){
return socket_;
}
void Connection::Send(uint8_t* buffer, int length){
socket_.async_send(boost::asio::buffer(buffer, length), 0, handler);
}
// Result of operation. // Number of bytes sent.
void Connection::handler(const boost::system::error_code& error, std::size_t bytes_transferred ){
}
这些是这段代码在 Visual C++ 中产生的错误:
Error 1 error C3867: 'Connection::handler': function call missing argument list; use '&Connection::handler' to create a pointer to member d:\c++\ugs\accountserver\connection.cpp 19
Error 2 error C2780: 'void boost::asio::basic_stream_socket<Protocol>::async_send(const ConstBufferSequence &,WriteHandler)' : expects 2 arguments - 3 provided d:\c++\ugs\accountserver\connection.cpp 19
为什么会出现这些错误,我该如何解决?
最佳答案
Error 1 error C3867: 'Connection::handler': function call missing argument list; use '&Connection::handler' to create a pointer to member d:\c++\ugs\accountserver\connection.cpp 19
第一个错误告诉您:要获取成员函数的“地址”,您需要使用以下语法:
&Connection::handler
Error 2 error C2780: 'void boost::asio::basic_stream_socket<Protocol>::async_send(const ConstBufferSequence &,WriteHandler)' : expects 2 arguments - 3 provided d:\c++\ugs\accountserver\connection.cpp 19
第二个错误告诉您传递给函数的参数数量不匹配
所以调用async_send
的正确方法是
socket_.async_send(boost::asio::buffer(buffer, length), boost::bind(&Connection::handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
关于c++ - boost::asio async_send 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6082481/
[免责声明] 我是 boost 新手。 研究 boost::asio 并尝试创建一个具有以下功能的简单异步 TCP 服务器: 监听端口 13 上的连接 连接后,接收数据 如果收到的数据 == 时间,则
我有下一个片段: void TcpConnection::Send(const std::vector& buffer) { std::shared_ptr> bufferCopy = std::ma
以下使用 boost::asio 的代码将无法编译: #pragma once #include #include #include #include #include #include
尝试为一种行为类似于回显服务器的服务器编写客户端。当我尝试发送内容时,它会发出哔哔声。我发现问题出现在 win_iocp_socket_service_base.ipp 文件的第 356 行(在我的编
我将 Boost.Asio 用于我正在编写的服务器应用程序。 async_send 要求调用方保留对正在发送的数据的所有权,直到数据发送成功。这意味着我的代码(如下所示)将失败,而且确实如此,因为 d
我做了一个静态库。我在中创建了这三个类 连接类 #ifndef _CONNECTION_H_ #define _CONNECTION_H_ #include #include #include
我刚才才注意到boost::asio中的async_write_some和async_send(第二次重载)函数是完全一样的: async_write_some 定义: ... template
我知道调用 boost::asio::ip::tcp::socket::async_receive(或 boost::asio::ip::tcp::socket::async_send) 两次可能会导
当 error_code 不为 0 时,连接是否正式“失效”? 当 error_code 不为 0 时,读取处理程序的 bytesReceived 参数是否可能为 0 以外的任何值?如果可能,是否应该
我是一名优秀的程序员,十分优秀!