mirror of
https://gitee.com/openharmony/third_party_nghttp2
synced 2025-02-14 13:44:37 +00:00
asio: Fix resource leak (socket not closed) in server code
This commit is contained in:
parent
f6f908a541
commit
7d753d779e
@ -82,7 +82,9 @@ server::server(const std::string &address, uint16_t port,
|
|||||||
acceptors_.push_back(std::move(acceptor));
|
acceptors_.push_back(std::move(acceptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
start_accept();
|
for (auto &acceptor : acceptors_) {
|
||||||
|
start_accept(acceptor);
|
||||||
|
}
|
||||||
|
|
||||||
start_timer();
|
start_timer();
|
||||||
}
|
}
|
||||||
@ -109,48 +111,44 @@ void server::start_timer() {
|
|||||||
|
|
||||||
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
|
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
|
||||||
|
|
||||||
void server::start_accept() {
|
void server::start_accept(boost::asio::ip::tcp::acceptor &acceptor) {
|
||||||
if (ssl_ctx_) {
|
if (ssl_ctx_) {
|
||||||
auto new_connection = std::make_shared<connection<ssl_socket>>(
|
auto new_connection = std::make_shared<connection<ssl_socket>>(
|
||||||
request_cb_, io_service_pool_.get_io_service(), *ssl_ctx_);
|
request_cb_, io_service_pool_.get_io_service(), *ssl_ctx_);
|
||||||
|
|
||||||
for (auto &acceptor : acceptors_) {
|
acceptor.async_accept(
|
||||||
acceptor.async_accept(
|
new_connection->socket().lowest_layer(),
|
||||||
new_connection->socket().lowest_layer(),
|
[this, &acceptor, new_connection](const boost::system::error_code &e) {
|
||||||
[this, new_connection](const boost::system::error_code &e) {
|
if (!e) {
|
||||||
if (!e) {
|
new_connection->socket().lowest_layer().set_option(
|
||||||
new_connection->socket().lowest_layer().set_option(
|
boost::asio::ip::tcp::no_delay(true));
|
||||||
boost::asio::ip::tcp::no_delay(true));
|
new_connection->socket().async_handshake(
|
||||||
new_connection->socket().async_handshake(
|
boost::asio::ssl::stream_base::server,
|
||||||
boost::asio::ssl::stream_base::server,
|
[new_connection](const boost::system::error_code &e) {
|
||||||
[new_connection](const boost::system::error_code &e) {
|
if (!e) {
|
||||||
if (!e) {
|
new_connection->start();
|
||||||
new_connection->start();
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
start_accept();
|
start_accept(acceptor);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
auto new_connection =
|
auto new_connection =
|
||||||
std::make_shared<connection<boost::asio::ip::tcp::socket>>(
|
std::make_shared<connection<boost::asio::ip::tcp::socket>>(
|
||||||
request_cb_, io_service_pool_.get_io_service());
|
request_cb_, io_service_pool_.get_io_service());
|
||||||
|
|
||||||
for (auto &acceptor : acceptors_) {
|
acceptor.async_accept(
|
||||||
acceptor.async_accept(
|
new_connection->socket(),
|
||||||
new_connection->socket(),
|
[this, &acceptor, new_connection](const boost::system::error_code &e) {
|
||||||
[this, new_connection](const boost::system::error_code &e) {
|
if (!e) {
|
||||||
if (!e) {
|
new_connection->socket().set_option(
|
||||||
new_connection->socket().set_option(
|
boost::asio::ip::tcp::no_delay(true));
|
||||||
boost::asio::ip::tcp::no_delay(true));
|
new_connection->start();
|
||||||
new_connection->start();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
start_accept();
|
start_accept(acceptor);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// Initiate an asynchronous accept operation.
|
/// Initiate an asynchronous accept operation.
|
||||||
void start_accept();
|
void start_accept(boost::asio::ip::tcp::acceptor &acceptor);
|
||||||
|
|
||||||
void start_timer();
|
void start_timer();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user