From 99584f2512513ed279b4cd6c78626c0ef057007b Mon Sep 17 00:00:00 2001 From: GeorgyKirichenko Date: Wed, 18 Jan 2017 22:28:49 +0300 Subject: [PATCH] Add io wait callback for blockin io operations. Add a io wait callback that will be called instead of base io witing handlers. --- include/ma_common.h | 1 + include/mysql.h | 3 ++- libmariadb/mariadb_lib.c | 12 ++++++------ plugins/pvio/pvio_npipe.c | 7 +++++++ plugins/pvio/pvio_socket.c | 7 +++++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/ma_common.h b/include/ma_common.h index 01f7ba161..d5b268665 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -71,6 +71,7 @@ struct st_mysql_options_extension { char *server_public_key; char *proxy_header; size_t proxy_header_len; + int (*io_wait)(my_socket handle, my_bool is_read, int timeout); }; typedef struct st_connection_handler diff --git a/include/mysql.h b/include/mysql.h index 08525e826..ef41db5f0 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -233,7 +233,8 @@ extern const char *SQLSTATE_UNKNOWN; MARIADB_OPT_MULTI_RESULTS, MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPT_INTERACTIVE, - MARIADB_OPT_PROXY_HEADER + MARIADB_OPT_PROXY_HEADER, + MARIADB_OPT_IO_WAIT }; enum mariadb_value { diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 3a4297878..0286dab0d 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -3015,6 +3015,9 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MYSQL_OPT_TLS_VERSION: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_version, (char *)arg1); break; + case MARIADB_OPT_IO_WAIT: + mysql->options.extension->io_wait = (int(*)(my_socket, my_bool, int))arg1; + break; default: va_end(ap); return(-1); @@ -3105,12 +3108,6 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) case MYSQL_OPT_NONBLOCK: *((my_bool *)arg)= test(mysql->options.extension && mysql->options.extension->async_context); break; - case MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS: - if (*(my_bool *)arg) - mysql->options.client_flag |= CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS; - else - mysql->options.client_flag &= ~CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS; - break; case MYSQL_OPT_SSL_ENFORCE: *((my_bool *)arg)= mysql->options.use_ssl; break; @@ -3229,6 +3226,9 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) case MARIADB_OPT_CONNECTION_HANDLER: *((char **)arg)= mysql->options.extension ? mysql->options.extension->connection_handler : NULL; break; + case MARIADB_OPT_IO_WAIT: + *((int(**)(my_socket, my_bool, int))arg) = mysql->options.extension->io_wait; + break; default: va_end(ap); return(-1); diff --git a/plugins/pvio/pvio_npipe.c b/plugins/pvio/pvio_npipe.c index cf95ede8e..b9430310c 100644 --- a/plugins/pvio/pvio_npipe.c +++ b/plugins/pvio/pvio_npipe.c @@ -162,6 +162,13 @@ ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) int pvio_npipe_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout) { + if (pvio->mysql->options.extension->io_wait != NULL) { + HANDLE handle; + if (pvio_npipe_get_handle(pvio, &handle)) + return 0; + return pvio->mysql->options.extension->io_wait(handle, is_read, timeout); + } + DWORD status; int save_error; struct st_pvio_npipe *cpipe= NULL; diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 888264c9e..833b2e21f 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -504,6 +504,13 @@ int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int time if (!pvio || !pvio->data) return 0; + if (pvio->mysql->options.extension->io_wait != NULL) { + my_socket handle; + if (pvio_socket_get_handle(pvio, &handle)) + return 0; + return pvio->mysql->options.extension->io_wait(handle, is_read, timeout); + } + csock= (struct st_pvio_socket *)pvio->data; { #ifndef _WIN32