当我尝试在断开连接后直接重新连接客户端时,我在服务器端(带有fork()的多进程服务器)发生了这个异常。我正在使用boost,但是现在我不理解抛出异常的确切指令,因为多进程中的调试不仅仅适合我。
但是我想在这一点上:
io_service_.notify_fork(boost::asio::io_service::fork_child);
有什么想法吗?
更新
我正在使用1.52版本的asio,所以它支持fork,异常在子进程中。它发生在第三次重新连接尝试,所以如果
这是代码:
if (fork() == 0) //I'm child process
{
io_service_.notify_fork(boost::asio::io_service::fork_prepare);
cout << "I'm child process and my PID is " << getpid() << endl;
/*Notifies to the io_service_ the fork termination*/
try
{
io_service_.notify_fork(boost::asio::io_service::fork_child);
}
catch (boost::exception& e)
{ cout<<"Exception in notify_fork child "<< endl;
std::cerr << diagnostic_information(e) << std::endl;
}
/*Closes the listen socket which remains opened in the parent process to accept new connections*/
acceptor_.close();
}
else //I'm the parent process
{
cout << "I'm the parent process and my PID is " << getpid() << endl;
/*Notifies to the io_service_ the fork termination*/
try
{
io_service_.notify_fork(boost::asio::io_service::fork_parent);
}
catch (boost::exception& e)
{
cout<<"Exception in notify_fork parent "<< endl;
std::cerr << diagnostic_information(e) << std::endl;
}
socket_.close();
/*Listening to new connections*/
start_accept();
}