aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Whitlock <bitcoin@mattwhitlock.name>2018-02-23 14:02:37 -0500
committerMatt Whitlock <bitcoin@mattwhitlock.name>2023-01-07 14:11:07 -0500
commit691eaf8873fe2f189153ca637506a0291504c97a (patch)
tree5a84f6e19fc250d9d710630c300049b0cf50ce4f
parentc41a1162ac4da437c5d755e8fe2bf636bed22b0f (diff)
downloadbitcoin-691eaf8873fe2f189153ca637506a0291504c97a.tar.xz
Pass MSG_MORE flag when sending non-final network messages
Since Nagle's algorithm is disabled, each and every call to send(2) can potentially generate a separate TCP segment on the wire. This is especially inefficient when sending the tiny header preceding each message payload. Linux implements a MSG_MORE flag that tells the kernel not to push the passed data immediately to the connected peer but rather to collect it in the socket's internal transmit buffer where it can be combined with data from successive calls to send(2). Where available, specify this flag when calling send(2) in CConnman::SocketSendData(CNode &) if the data buffer being sent is not the last one in node.vSendMsg.
-rw-r--r--src/net.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp
index d94542887b..9db4b9c9e6 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -802,7 +802,13 @@ size_t CConnman::SocketSendData(CNode& node) const
if (!node.m_sock) {
break;
}
- nBytes = node.m_sock->Send(reinterpret_cast<const char*>(data.data()) + node.nSendOffset, data.size() - node.nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT);
+ int flags = MSG_NOSIGNAL | MSG_DONTWAIT;
+#ifdef MSG_MORE
+ if (it + 1 != node.vSendMsg.end()) {
+ flags |= MSG_MORE;
+ }
+#endif
+ nBytes = node.m_sock->Send(reinterpret_cast<const char*>(data.data()) + node.nSendOffset, data.size() - node.nSendOffset, flags);
}
if (nBytes > 0) {
node.m_last_send = GetTime<std::chrono::seconds>();