Skip to content

Commit

Permalink
Add io wait callback for blockin io operations.
Browse files Browse the repository at this point in the history
Add a io wait callback that will be called instead of base io witing
handlers.
  • Loading branch information
GeorgyKirichenko authored and bigbes committed Oct 13, 2018
1 parent 4fbcc17 commit 99584f2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/ma_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions plugins/pvio/pvio_npipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions plugins/pvio/pvio_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99584f2

Please sign in to comment.