summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorunknown <kroki/tomash@moonlight.intranet>2006-08-14 20:01:19 +0400
committerunknown <kroki/tomash@moonlight.intranet>2006-08-14 20:01:19 +0400
commit32741794a3d50038f66871b49dfc3c26f4285e19 (patch)
tree06565f2fc9492fafb30c77e4dd7613366eaab02c /vio
parent04d60b389701329d934ed2f7690cc2fd686b9f4a (diff)
downloadmariadb-git-32741794a3d50038f66871b49dfc3c26f4285e19.tar.gz
BUG#9678: Client library hangs after network communication failure
Socket timeouts in client library were used only on Windows. The solution is to use socket timeouts in client library on all systems were they are supported. No test case is provided because it is impossible to simulate network failure in current test suit. sql/net_serv.cc: Retry indefinitely only if got EINTR. vio/viosocket.c: Set socket timeouts on POSIX systems as well as on Windows.
Diffstat (limited to 'vio')
-rw-r--r--vio/viosocket.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/vio/viosocket.c b/vio/viosocket.c
index 8d4c2387632..847e036d3b2 100644
--- a/vio/viosocket.c
+++ b/vio/viosocket.c
@@ -333,16 +333,30 @@ my_bool vio_poll_read(Vio *vio,uint timeout)
}
-void vio_timeout(Vio *vio __attribute__((unused)),
- uint which __attribute__((unused)),
- uint timeout __attribute__((unused)))
+void vio_timeout(Vio *vio, uint which, uint timeout)
{
+/* TODO: some action should be taken if socket timeouts are not supported. */
+#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
+
#ifdef __WIN__
- ulong wait_timeout= (ulong) timeout * 1000;
- (void) setsockopt(vio->sd, SOL_SOCKET,
- which ? SO_SNDTIMEO : SO_RCVTIMEO, (char*) &wait_timeout,
- sizeof(wait_timeout));
-#endif /* __WIN__ */
+
+ /* Windows expects time in milliseconds as int. */
+ int wait_timeout= (int) timeout * 1000;
+
+#else /* ! __WIN__ */
+
+ /* POSIX specifies time as struct timeval. */
+ struct timeval wait_timeout;
+ wait_timeout.tv_sec= timeout;
+ wait_timeout.tv_usec= 0;
+
+#endif /* ! __WIN__ */
+
+ /* TODO: return value should be checked. */
+ (void) setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
+ (char*) &wait_timeout, sizeof(wait_timeout));
+
+#endif /* defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO) */
}