changeset 22113:50c9dc00154d

Add timeout to tcp connections, avoid hanging forever. Based on patch for bugzilla #673
author rtogni
date Sun, 04 Feb 2007 14:18:56 +0000
parents c9214f2c30c4
children 9bc7a6022cde
files stream/tcp.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/stream/tcp.c	Sun Feb 04 14:02:35 2007 +0000
+++ b/stream/tcp.c	Sun Feb 04 14:18:56 2007 +0000
@@ -86,6 +86,13 @@
 		return TCP_ERROR_FATAL;
 	}
 
+#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));
+#endif
+
 	switch (af) {
 		case AF_INET:  our_s_addr = (void *) &server_address.four.sin_addr; break;
 #ifdef HAVE_AF_INET6