Skip to content

Commit 691eaf8

Browse files
committed
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.
1 parent c41a116 commit 691eaf8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/net.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,13 @@ size_t CConnman::SocketSendData(CNode& node) const
802802
if (!node.m_sock) {
803803
break;
804804
}
805-
nBytes = node.m_sock->Send(reinterpret_cast<const char*>(data.data()) + node.nSendOffset, data.size() - node.nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT);
805+
int flags = MSG_NOSIGNAL | MSG_DONTWAIT;
806+
#ifdef MSG_MORE
807+
if (it + 1 != node.vSendMsg.end()) {
808+
flags |= MSG_MORE;
809+
}
810+
#endif
811+
nBytes = node.m_sock->Send(reinterpret_cast<const char*>(data.data()) + node.nSendOffset, data.size() - node.nSendOffset, flags);
806812
}
807813
if (nBytes > 0) {
808814
node.m_last_send = GetTime<std::chrono::seconds>();

0 commit comments

Comments
 (0)