From 3a8d4bdbe6d264d8f93c75dc62f61ec41e9e7462 Mon Sep 17 00:00:00 2001
From: dscho <dscho>
Date: Fri, 9 Dec 2005 13:56:25 +0000
Subject: work around write() returning ENOENT on Solaris 2.7

---
 ChangeLog              | 4 ++++
 configure.ac           | 8 ++++++++
 libvncclient/sockets.c | 6 +++++-
 libvncserver/sockets.c | 3 +++
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 5971e66..8303149 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-12-08  "Mazin, Malvina" <Malvina.Mazin@kla-tencor.com>
+	* configure.ac, libvncserver/sockets.c: on Solaris 2.7, write may
+	  return ENOENT when it really means EAGAIN.
+
 2005-12-07  Giampiero Giancipoli <giampiero.giancipoli@fredreggiane.com>
 	* libvncclient/vncviewer.c: plug memory leaks
 
diff --git a/configure.ac b/configure.ac
index abb338a..5fe134d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -360,6 +360,14 @@ AM_CONDITIONAL(LINUX, test -c /dev/vcsa1)
 AC_CHECK_HEADER(ApplicationServices/ApplicationServices.h, HAVE_OSX="true")
 AM_CONDITIONAL(OSX, test "$HAVE_OSX" = "true")
 
+# On Solaris 2.7, write() returns ENOENT when it really means EAGAIN
+AH_TEMPLATE(ENOENT_WORKAROUND, [work around when write() returns ENOENT but does not mean it])
+case `(uname -sr) 2>/dev/null` in
+    "SunOS 5.7")
+	AC_DEFINE(ENOENT_WORKAROUND)
+    ;;
+esac
+
 # Check for rpm SOURCES path
 printf "checking for rpm sources path... "
 RPMSOURCEDIR="NOT-FOUND"
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c
index 6ee5a9d..aca38aa 100644
--- a/libvncclient/sockets.c
+++ b/libvncclient/sockets.c
@@ -217,7 +217,11 @@ WriteToRFBServer(rfbClient* client, char *buf, int n)
     j = write(client->sock, buf + i, (n - i));
     if (j <= 0) {
       if (j < 0) {
-	if (errno == EWOULDBLOCK || errno == EAGAIN) {
+	if (errno == EWOULDBLOCK ||
+#ifdef LIBVNCSERVER_ENOENT_WORKAROUND
+		errno == ENOENT ||
+#endif
+		errno == EAGAIN) {
 	  FD_ZERO(&fds);
 	  FD_SET(client->sock,&fds);
 
diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c
index ca8b995..a225131 100755
--- a/libvncserver/sockets.c
+++ b/libvncserver/sockets.c
@@ -447,6 +447,9 @@ rfbReadExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
 	    if (errno == EINTR)
 		continue;
 
+#ifdef LIBVNCSERVER_ENOENT_WORKAROUND
+	    if (errno != ENOENT)
+#endif
             if (errno != EWOULDBLOCK && errno != EAGAIN) {
                 return n;
             }
-- 
cgit v1.2.3

