summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPeter Åstrand (astrand) <astrand@cendio.se>2017-10-10 13:56:51 +0200
committerPeter Åstrand (astrand) <astrand@cendio.se>2017-11-08 10:40:13 +0100
commite2c3b60f32d63590fb17be5342586177b5e72147 (patch)
tree3b2583268c6c12fa308421b8a4894d64753d3feb /common
parent01dc1a67dc5afad21822930d34b2b44eec414790 (diff)
downloadtigervnc-e2c3b60f32d63590fb17be5342586177b5e72147.tar.gz
tigervnc-e2c3b60f32d63590fb17be5342586177b5e72147.zip
Use send() with MSG_DONTWAIT when possible
Diffstat (limited to 'common')
-rw-r--r--common/rdr/FdOutStream.cxx10
1 files changed, 9 insertions, 1 deletions
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 <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
+#include <sys/socket.h>
#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)