diff options
author | unknown <knielsen@knielsen-hq.org> | 2012-02-21 22:15:44 +0100 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2012-02-21 22:15:44 +0100 |
commit | f6b68a10707c95e24f67d338eaaa03f1bd575598 (patch) | |
tree | bd7748f0d0a239145e4c02b223f523b4c571aacb /vio | |
parent | 4b9907979ce316be12a7ce2b62874b42edf2e39e (diff) | |
parent | 7c8ebb532eef543a9b98107c164a12a49e28d0ca (diff) | |
download | mariadb-git-f6b68a10707c95e24f67d338eaaa03f1bd575598.tar.gz |
Merge MWL#192: Non-blocking client library, into MariaDB 5.5.
Diffstat (limited to 'vio')
-rw-r--r-- | vio/viosocket.c | 48 | ||||
-rw-r--r-- | vio/viossl.c | 12 |
2 files changed, 53 insertions, 7 deletions
diff --git a/vio/viosocket.c b/vio/viosocket.c index 6a33937d4bd..f68fe02f213 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -24,6 +24,8 @@ */ #include "vio_priv.h" +#include "my_context.h" +#include <mysql_async.h> #ifdef FIONREAD_IN_SYS_FILIO # include <sys/filio.h> @@ -44,12 +46,26 @@ size_t vio_read(Vio * vio, uchar* buf, size_t size) /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ DBUG_ASSERT(vio->read_end == vio->read_pos); + if (vio->async_context && vio->async_context->active) + r= my_recv_async(vio->async_context, vio->sd, buf, size, vio->read_timeout); + else + { + if (vio->async_context) + { + /* + If switching from non-blocking to blocking API usage, set the socket + back to blocking mode. + */ + my_bool old_mode; + vio_blocking(vio, TRUE, &old_mode); + } #ifdef __WIN__ - r = recv(vio->sd, buf, size,0); + r = recv(vio->sd, buf, size,0); #else - errno=0; /* For linux */ - r = read(vio->sd, buf, size); + errno=0; /* For linux */ + r = read(vio->sd, buf, size); #endif /* __WIN__ */ + } #ifndef DBUG_OFF if (r == (size_t) -1) { @@ -116,11 +132,26 @@ size_t vio_write(Vio * vio, const uchar* buf, size_t size) DBUG_ENTER("vio_write"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); + if (vio->async_context && vio->async_context->active) + r= my_send_async(vio->async_context, vio->sd, buf, size, + vio->write_timeout); + else + { + if (vio->async_context) + { + /* + If switching from non-blocking to blocking API usage, set the socket + back to blocking mode. + */ + my_bool old_mode; + vio_blocking(vio, TRUE, &old_mode); + } #ifdef __WIN__ - r = send(vio->sd, buf, size,0); + r = send(vio->sd, buf, size,0); #else - r = write(vio->sd, buf, size); + r = write(vio->sd, buf, size); #endif /* __WIN__ */ + } #ifndef DBUG_OFF if (r == (size_t) -1) { @@ -634,6 +665,8 @@ my_bool vio_poll_read(Vio *vio, uint timeout) { my_socket sd= vio->sd; DBUG_ENTER("vio_poll_read"); + if (vio->async_context && vio->async_context->active) + DBUG_RETURN(my_poll_read_async(vio->async_context, timeout)); #ifdef HAVE_OPENSSL if (vio->type == VIO_TYPE_SSL) sd= SSL_get_fd((SSL*) vio->ssl_arg); @@ -722,6 +755,11 @@ void vio_timeout(Vio *vio, uint which, uint timeout) thr_alarm or just run without read/write timeout(s) */ #endif + /* Make timeout values available for async operations. */ + if (which) + vio->write_timeout= timeout; + else + vio->read_timeout= timeout; } diff --git a/vio/viossl.c b/vio/viossl.c index b40f7b931e6..48881cc2903 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -21,6 +21,8 @@ */ #include "vio_priv.h" +#include "my_context.h" +#include <mysql_async.h> #ifdef HAVE_OPENSSL @@ -66,7 +68,10 @@ size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx", vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg)); - r= SSL_read((SSL*) vio->ssl_arg, buf, size); + if (vio->async_context && vio->async_context->active) + r= my_ssl_read_async(vio->async_context, (SSL *)vio->ssl_arg, buf, size); + else + r= SSL_read((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); @@ -83,7 +88,10 @@ size_t vio_ssl_write(Vio *vio, const uchar* buf, size_t size) DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); - r= SSL_write((SSL*) vio->ssl_arg, buf, size); + if (vio->async_context && vio->async_context->active) + r= my_ssl_write_async(vio->async_context, (SSL *)vio->ssl_arg, buf, size); + else + r= SSL_write((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); |