Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add io wait callback for blockin io operations. #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ extern const char *SQLSTATE_UNKNOWN;
/* MariaDB specific */
MYSQL_PROGRESS_CALLBACK=5999,
MYSQL_OPT_NONBLOCK,
MYSQL_OPT_IO_WAIT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New options (which are not supported by MySQL server should be prefixed with MariaDB and should be added to the end of enumeration.

/* MariaDB Connector/C specific */
MYSQL_DATABASE_DRIVER=7000,
MARIADB_OPT_SSL_FP, /* deprecated, use MARIADB_OPT_TLS_PEER_FP instead */
Expand Down Expand Up @@ -316,6 +317,7 @@ struct st_mysql_options {
int (*local_infile_error)(void *, char *, unsigned int);
void *local_infile_userdata;
struct st_mysql_options_extension *extension;
int (*io_wait)(my_socket handle, my_bool is_read, int timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added to mysql->options.extension to avoid ABI breakage.

};

typedef struct st_mysql {
Expand Down
6 changes: 6 additions & 0 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,9 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
}
mysql->options.extension->async_context= ctxt;
break;
case MYSQL_OPT_IO_WAIT:
mysql->options.io_wait = (int(*)(my_socket, bool, int))arg1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callback should be registered in mysql->options.extension->io_wait

break;
case MYSQL_OPT_MAX_ALLOWED_PACKET:
if (mysql)
mysql->options.max_allowed_packet= (unsigned long)(*(size_t *)arg1);
Expand Down Expand Up @@ -3035,6 +3038,9 @@ 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_IO_WAIT:
*((int(**)(my_socket, my_bool, int))arg) = mysql->options.io_wait;
break;
case MYSQL_OPT_SSL_ENFORCE:
*((my_bool *)arg)= mysql->options.use_ssl;
break;
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.io_wait != NULL) {
HANDLE handle;
if (pvio_npipe_get_handle(pvio, &handle))
return 0;
return pvio->mysql->options.io_wait(handle, is_read, timeout);
}

int r= -1;
DWORD status;
int save_error;
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 @@ -500,6 +500,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.io_wait != NULL) {
my_socket handle;
if (pvio_socket_get_handle(pvio, &handle))
return 0;
return pvio->mysql->options.io_wait(handle, is_read, timeout);
}

csock= (struct st_pvio_socket *)pvio->data;
{
#ifndef _WIN32
Expand Down