From e2c3b60f32d63590fb17be5342586177b5e72147 Mon Sep 17 00:00:00 2001 From: "Peter Åstrand (astrand)" Date: Tue, 10 Oct 2017 13:56:51 +0200 Subject: Use send() with MSG_DONTWAIT when possible --- common/rdr/FdOutStream.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx index 29e864fc..32245a6b 100644 --- a/common/rdr/FdOutStream.cxx +++ b/common/rdr/FdOutStream.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #endif /* Old systems have select() in sys/time.h */ @@ -193,7 +194,14 @@ int FdOutStream::writeWithTimeout(const void* data, int length, int timeoutms) return 0; do { - n = ::write(fd, data, length); + // select only guarantees that you can write SO_SNDLOWAT without + // blocking, which is normally 1. Use MSG_DONTWAIT to avoid + // blocking, when possible. +#ifndef MSG_DONTWAIT + n = ::send(fd, (const char*)data, length, 0); +#else + n = ::send(fd, (const char*)data, length, MSG_DONTWAIT); +#endif } while (n < 0 && (errno == EINTR)); if (n < 0) -- cgit v1.2.3