summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorunknown <kroki/tomash@moonlight.intranet>2006-09-18 22:02:06 +0400
committerunknown <kroki/tomash@moonlight.intranet>2006-09-18 22:02:06 +0400
commit0b2a28f5cf69237f501b075dd3cfde318768fce8 (patch)
tree239a22917b95abda36af68025cb1329170dc0517 /vio
parentdcb665900136fb4015589680c612add8abf1deca (diff)
downloadmariadb-git-0b2a28f5cf69237f501b075dd3cfde318768fce8.tar.gz
BUG#9678: Client library hangs after network communication failure
(back-port to 4.0) Socket timeouts in client library were used only on Windows. Additionally, in 4.0 write operations erroneously set read timeout. The solution is to use socket timeouts in client library on all systems were they are supported, and to differentiate between read and write timeouts. No test case is provided because it is impossible to simulate network failure in current test suite. include/violite.h: Add argument to vio_timeout() to determine which timeout should be set: for read (false) or for write (true). libmysqld/lib_vio.c: Add argument to vio_timeout() to determine which timeout should be set: for read (false) or for write (true). sql/net_serv.cc: Add argument to vio_timeout() to determine which timeout should be set: for read (false) or for write (true). vio/viosocket.c: Add argument to vio_timeout() to determine which timeout should be set: for read (false) or for write (true). Implement socket timeouts on POSIX systems.
Diffstat (limited to 'vio')
-rw-r--r--vio/viosocket.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/vio/viosocket.c b/vio/viosocket.c
index 7ea130c9949..2738f7743dc 100644
--- a/vio/viosocket.c
+++ b/vio/viosocket.c
@@ -345,12 +345,26 @@ my_bool vio_poll_read(Vio *vio,uint timeout)
}
-void vio_timeout(Vio *vio __attribute__((unused)),
- uint timeout __attribute__((unused)))
+void vio_timeout(Vio *vio, uint which, uint timeout)
{
+#if defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)
+
#ifdef __WIN__
- ulong wait_timeout= (ulong) timeout * 1000;
- (void) setsockopt(vio->sd, SOL_SOCKET, 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__ */
+
+ (void) setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
+ (char*) &wait_timeout, sizeof(wait_timeout));
+
+#endif /* defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO) */
}