boost::asio async_accept总是发生错误,error_code.value() 是 22,这意味着参
boost::asio async_accept always occur a error, error_code.value() is 22, which means invalid argument
我使用了boost::asio,有8个线程
boost::asio::io_service ios;
boost::asio::ip::tcp::acceptor(ios);
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
acceptor.open(endpoint.protocol());
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
acceptor.listen();
LocalTcpServer::getInstance()->initialize(ios, acceptor, pool);
boost::thread_group th_group;
for(i=0; i< 8; i++)
th_group.add_thread(new boost::thread(boost::bind(&boost::asio::io_service::run, &ios)));
th_group.join_all();
session::start()
{
socket.async_read_some(boost::asio::buffer(buffer), m_strand.wrap(boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)))
}
session::handleread(boost::system::error_code &e, size_t byteTrans)
{
if(e || byteTrans == 0 )
{
socket.shutdown(...)
//socketRelease close the socket and delete this
timeInfo->timer->async_wait(boost::bind(socketRelease(), ...);
}
else
{
//deal with data whit pool;
}
socket.async_read_some(.....);
}
LocaltcpServer::initialize(ios, acceptor, pool){
//init, pool is inherit from threadpool, used in handle read to deal with receive data
...;
startaccept();
}
LocalTcpServer::Accept()
{
session* pSession = new session(acceptor->get_io_service, pool);
acceptor.async_accept(session->socket, boost::bind(handle_accept, this, pSession, boost::asio::placeholder::error))
}
LocalTcpServer::handle_accept(boost::system::error_code& e; ... );
{
if(e)
{
//when app run sometime(serveral hours or days, e has always error 22, means invalid argument )
LOG_ERROR << e.message() << e.value();
delete newSession;
accept();
}
else
{
session.start();
accept();
}
}
该应用程序起初工作正常,但有时,可能会在几个小时内,1 或两天后,错误来了,hander_accpte总是得到一个错误的、无效的参数。 所以,没有新的连接,
套接字连接几乎是10000,文件打开限制是65535, 并且我使用netstat检查插座是否正常关闭,没有关闭的插座 我想知道为什么会发生错误,我该如何解决它, 或者如果我的代码有一些错误? 我希望我把这个问题描述清楚。谢谢。
如果侦听套接字也失败了,则主要嫌疑人之一是 dhcp。接口的 IP 地址可能已更改。
在这种情况下,绑定到该接口的所有打开套接字都将失效,必须关闭,包括侦听套接字,然后必须使用新套接字重新启动侦听。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 这行代码在C++类中意味着什么
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 这对"With a stackless coroutine, only the top-level routine may be suspended."意味着什么
- 寻找地理和伤害意味着超载
- 为什么我会" void value not ignored as it ought to be"?
- 方法错误"not all control paths return a value"和方法不返回值
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- 如何在 c++ 中理解这样的代码 [request->headers().Method()->value().getStringView())]
- std::<key-value>不同类型的对向量
- c++ visual studio 64bit | save registers value
- 初始化数组、"memset"或" {//value} "的最佳方法是什么?
- 在C++标准中做格式好意味着代码可以编译
- 如何解决类成员函数中的"return a value"错误?
- bsoncxx: document::view vs document::value
- .value( "key" , default) 不适用于空的 json 对象吗?
- boost::asio async_accept总是发生错误,error_code.value() 是 22,这意味着参
- 在这个程序中"getavg must return value"意味着什么?
- 同样的'value'对于 std::set 意味着什么?