remove TCP_NODELAY socket option, refactor when SO_LINGER is set on the socket options; correct some file formatting;

pull/33/head
Bryan Biedenkapp 3 years ago
parent 8c15cb5b50
commit ca7eb1a407

@ -83,6 +83,7 @@ namespace network
{ {
try try
{ {
ensureNoLinger();
if (m_socket.is_open()) { if (m_socket.is_open()) {
m_socket.close(); m_socket.close();
} }
@ -90,6 +91,14 @@ namespace network
catch(const std::exception&) { /* ignore */ } catch(const std::exception&) { /* ignore */ }
} }
/// <summary>Helper to enable the SO_LINGER socket option during shutdown.</summary>
void ensureNoLinger()
{
// enable SO_LINGER timeout 0
asio::socket_base::linger linger(true, 0);
m_socket.set_option(linger);
}
/// <summary>Perform an synchronous write operation.</summary> /// <summary>Perform an synchronous write operation.</summary>
void send(HTTPPayload request) void send(HTTPPayload request)
{ {
@ -126,9 +135,7 @@ namespace network
} }
} }
else if (ec != asio::error::operation_aborted) { else if (ec != asio::error::operation_aborted) {
if (m_socket.is_open()) { stop();
m_socket.close();
}
} }
}); });
} }

@ -164,14 +164,6 @@ namespace network
{ {
asio::connect(m_socket, endpoints); asio::connect(m_socket, endpoints);
// enable SO_LINGER timeout 0
asio::socket_base::linger linger(true, 0);
m_socket.set_option(linger);
// enable TCP_NODELAY
asio::ip::tcp::no_delay noDelay(true);
m_socket.set_option(noDelay);
m_connection = new_unique(ConnectionType, std::move(m_socket), m_requestHandler); m_connection = new_unique(ConnectionType, std::move(m_socket), m_requestHandler);
m_connection->start(); m_connection->start();
} }

@ -90,7 +90,7 @@ namespace network
void stopAll() void stopAll()
{ {
for (auto c : m_connections) for (auto c : m_connections)
c->stop(); c->stop();
std::lock_guard<std::mutex> guard(m_lock); std::lock_guard<std::mutex> guard(m_lock);
m_connections.clear(); m_connections.clear();

Loading…
Cancel
Save

Powered by TurnKey Linux.