[gtk-vnc-devel] [PATCH 3/4] Use Gnulib ioctl instead of ioctlsocket



This patch isn't necessary for Windows itself, but is important for
Wine.  Wine apparently contains a bug where calls to ioctlsocket fail
because it tries to interpret the first parameter as a handle.[1]

This calls Gnulib's replacement ioctl function instead.  It also
rearranges the code so that the normal Unix case is first, and the
Windows case second.  Also it uses WIN32 instead of __MINGW32__ as
explained in patch 1/4.

Rich.

[1] Actually, I'm not totally sure this analysis is correct -- it's
very hard to follow what the code is doing and what it's supposed to
be doing.  Furthermore the concept of file descriptor vs socket vs
handle is very confused on Windows itself.  In any case, this patch is
still necessary to run gvncviewer.exe under Wine.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
Read my OCaml programming blog: http://camltastic.blogspot.com/
Fedora now supports 68 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
diff -r 47135c91cd9c src/gvnc.c
--- a/src/gvnc.c	Thu Oct 09 11:23:09 2008 -0400
+++ b/src/gvnc.c	Wed Oct 29 14:51:26 2008 +0000
@@ -2832,13 +2832,7 @@
 
 static gboolean gvnc_set_nonblock(int fd)
 {
-#ifdef __MINGW32__
-	unsigned long flags = 1;
-	if (ioctlsocket(fd, FIONBIO, &flags) < 0) {
-		GVNC_DEBUG ("Failed to set nonblocking flag\n");
-		return FALSE;
-	}
-#else
+#ifndef WIN32
 	int flags;
 	if ((flags = fcntl(fd, F_GETFL)) < 0) {
 		GVNC_DEBUG ("Failed to fcntl()\n");
@@ -2849,7 +2843,20 @@
 		GVNC_DEBUG ("Failed to fcntl()\n");
 		return FALSE;
 	}
-#endif
+
+#else /* WIN32 */
+	unsigned long flag = 1;
+
+	/* This is actually Gnulib's replacement rpl_ioctl function.
+	 * We can't call ioctlsocket directly in any case.
+	 */
+	if (ioctl (fd, FIONBIO, (void *) &flag) == -1) {
+		GVNC_DEBUG ("Failed to set nonblocking flag, winsock error = %d",
+			    WSAGetLastError ());
+		return FALSE;
+	}
+#endif /* WIN32 */
+
 	return TRUE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]