我确信套接字在我的应用程序中到处都是关闭的,并且我不断在我的 /proc/pid/fd/ 下获取这个新创建的 fd/socket 文件,这很正常。我确定不是。
连接.cpp
connection::start() {
socket_.set_option(boost::asio::ip::tcp::no_delay(true));
boost::asio::socket_base::non_blocking_io command(true);
socket_.io_control(command);
read_header();
longevity_timer_.start();
// log_->debugStream() << "listening";
}
void connection::stop() {
cancel_timeout();
boost::system::error_code ignored_ec;
// initiate graceful connection closure & stop all asynchronous ops
try {
socket_.cancel();
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
if (ignored_ec)
{
log_->errorStream() << "shutdown: bad socket; couldn't close cleanly" << ignored_ec.message();
}
socket_.close(ignored_ec);
if (ignored_ec)
{
log_->errorStream() << "close: bad socket; couldn't close cleanly" << ignored_ec.message();
}
} catch (std::exception& e) {
log_->errorStream() << "bad socket; couldn't close cleanly";
}
}
lsof -p pid
dakwakd 20733 root 18u IPv4 647843 0t0 TCP localhost:35654->localhost:amqp (ESTABLISHED)
dakwakd 20733 root 19u IPv4 647969 0t0 TCP localhost:35695->localhost:amqp (ESTABLISHED)
dakwakd 20733 root 20u IPv4 647599 0t0 TCP localhost:35543->localhost:amqp (ESTABLISHED)
dakwakd 20733 root 21u IPv4 647634 0t0 TCP localhost:35567->localhost:amqp (ESTABLISHED)
现在,每次我得到一个新的连接时,我都会确保在完成后停止它。但是 /proc/pid/fd/ 下的 fd/socket 文件仍然快速增长
我怎样才能确保我没有做错任何事