线程-线程创建问题
Boost::Thread - thread create issue
我的服务器有一个问题(基于ASIO & &;Boost::线程)
In line:
this->connection->thread = boost::shared_ptr<boost::thread>(new boost::thread(worker, this->connection));
I got error:
Core/CCore.cpp: In member function 'void cocore::handle_accept(const .cpp)boost::系统:error_code&):
Core/CCore.cpp:71:163: error: no matching function for call to'bind(, core * const,boost:: arg<1>(,)())的
完整错误码:http://pastebin.com/PaftWzbx
核心定义&受体:
class CCore
{
public:
CCore(boost::asio::io_service *io_service, const boost::asio::ip::tcp::endpoint &endpoint);
bool failed;
private:
void handle_accept( const boost::system::error_code& error );
boost::asio::io_service *io_service;
boost::asio::ip::tcp::endpoint endpoint;
boost::asio::ip::tcp::acceptor *acceptor;
boost::shared_ptr<CConnection> connection;
};
void CCore::handle_accept(const boost::system::error_code& error)
{
if (error) {
// accept failed
//LOG(ERROR, "Acceptor failed: " << error.message());
return;
}
//LOG(INFO, "Accepted connection from " << this->connection->endpoint.address().to_string() << ":" << this->connection->endpoint.port());
this->connection->thread = boost::shared_ptr<boost::thread>(new boost::thread(worker, this->connection));
this->connection = boost::shared_ptr<CConnection>(new CConnection());
this->connection->master_io_service = this->io_service;
this->acceptor->async_accept(*(this->connection->socket), this->connection->endpoint, boost::bind(CCore::handle_accept, this, boost::asio::placeholders::error));
}
class CConnection {
public:
CConnection(void);
boost::asio::io_service io_service;
boost::shared_ptr<boost::asio::ip::tcp::socket> socket;
boost::asio::ip::tcp::endpoint endpoint;
boost::shared_ptr<boost::thread> thread;
boost::asio::io_service *master_io_service;
bool close;
};
void worker(boost::shared_ptr<CConnection> connection)
{
boost::asio::ip::tcp::socket &socket = *(connection->socket);
boost::asio::socket_base::non_blocking_io make_non_blocking(true);
socket.io_control(make_non_blocking);
char acBuffer[1024];
std::string line("");
while ( connection->close == false ) {
} // while connection not to be closed
}
有谁知道如何解决这个错误吗?谢谢。
由于handle_accept是core的成员函数,因此您需要更改boost::bind first参数:
boost::bind(CCore::handle_accept, ...
:
boost::bind(&CCore::handle_accept, ...
希望能有所帮助
相关文章:
- 尝试从头开始实现Leetcode的FizzBuzz多线程问题。收到"libc++abi.dylib: terminating"错误
- MFC执行线程问题
- 提升线程问题,当一个线程与另一个线程没有相同的副本时如何共享变量?
- VS2017 Linux C 线程问题
- 由于线程问题,Qt-Gui没有更新
- shared_ptr和线程问题
- 线程问题
- 奇怪的线程问题
- 显示Q对话框时出现QT线程问题
- gdal多线程问题
- Qt:QList线程问题
- C#封送以调用C++DLL.COM和线程问题
- C++ 线程问题
- C++11 多线程问题
- 消息框线程问题
- boost::d ynamic_bitset 多线程问题
- 标准::线程问题
- Android 的 c++11 多线程问题,其中某些线程未正确调度
- C++ 提升线程问题
- concurrent_vector vs 矢量与互斥锁,线程问题与push_back