RPC Binder: disable Nagle's algorithm
For some reason, I thought we did this - I thought it was
incidental to some other API we used. RPC Binder is an RPC
system, AND ONE WITH SYNCHRONOUS CALLS! It should not hold
these packets.
Bug: 271860373
Test: run inet cases before/after:
binderRpcTest --gtest_filter="*PerSocket/BinderRpc.RepeatBinderNull/inet_socket_tls_clientV0_serverV4026531840_single_threaded_no_kernel*"
before: 0m26.845s
after: 0m12.271s
Change-Id: Ib257b53cd2e4ca19041cdb5fd985be346e3fac5e
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 1a821f1..bba0bcb 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -20,6 +20,7 @@
#include <dlfcn.h>
#include <inttypes.h>
+#include <netinet/tcp.h>
#include <poll.h>
#include <unistd.h>
@@ -608,6 +609,18 @@
return -savedErrno;
}
+ if (addr.addr()->sa_family == AF_INET || addr.addr()->sa_family == AF_INET6) {
+ int noDelay = 1;
+ int result =
+ setsockopt(serverFd.get(), IPPROTO_TCP, TCP_NODELAY, &noDelay, sizeof(noDelay));
+ if (result < 0) {
+ int savedErrno = errno;
+ ALOGE("Could not set TCP_NODELAY on %s: %s", addr.toString().c_str(),
+ strerror(savedErrno));
+ return -savedErrno;
+ }
+ }
+
RpcTransportFd transportFd(std::move(serverFd));
if (0 != TEMP_FAILURE_RETRY(connect(transportFd.fd.get(), addr.addr(), addr.addrSize()))) {