changeset 22379:6b245d6e56a9

winsocks expects an int in milliseconds instead of struct timeval to set the timeout of a socket patch by Zuxy Meng, zuxy dot meng ... gmailcom
author ivo
date Thu, 01 Mar 2007 14:57:44 +0000
parents dc9d2940fc05
children e47d88c5cbc0
files stream/tcp.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/stream/tcp.c	Thu Mar 01 12:54:38 2007 +0000
+++ b/stream/tcp.c	Thu Mar 01 14:57:44 2007 +0000
@@ -77,6 +77,9 @@
 	
 #ifdef HAVE_WINSOCK2
 	u_long val;
+	int to;
+#else
+	struct timeval to;
 #endif
 	
 	socket_server_fd = socket(af, SOCK_STREAM, 0);
@@ -88,10 +91,15 @@
 	}
 
 #if defined(SO_RCVTIMEO) && defined(SO_SNDTIMEO)
-	tv.tv_sec = 10;
-	tv.tv_usec = 0;
-	setsockopt(socket_server_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
-	setsockopt(socket_server_fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+#ifdef HAVE_WINSOCK2
+	/* timeout in milliseconds */
+	to = 10 * 1000;
+#else
+	to.tv_sec = 10;
+	to.tv_usec = 0;
+#endif
+	setsockopt(socket_server_fd, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof(to));
+	setsockopt(socket_server_fd, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof(to));
 #endif
 
 	switch (af) {