diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 6e66d55c..269056ac 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -699,6 +699,7 @@ pvio_socket_connect_sync_or_async(MARIADB_PVIO *pvio, my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) { struct st_pvio_socket *csock= NULL; + struct timeval tm; if (!pvio || !cinfo) return 1; @@ -844,13 +845,27 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) goto error; } -#ifdef _WIN32 /* apply timeouts */ if (pvio->timeout[PVIO_WRITE_TIMEOUT] > 0) + { +#ifndef _WIN32 + tm.tv_sec= pvio->timeout[PVIO_WRITE_TIMEOUT] / 1000; + tm.tv_usec= pvio->timeout[PVIO_WRITE_TIMEOUT] % 1000; + setsockopt(csock->socket, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tm, sizeof(tm)); +#else setsockopt(csock->socket, SOL_SOCKET, SO_SNDTIMEO, (const char *)&pvio->timeout[PVIO_WRITE_TIMEOUT], sizeof(int)); - if (pvio->timeout[PVIO_READ_TIMEOUT] > 0) - setsockopt(csock->socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&pvio->timeout[PVIO_READ_TIMEOUT], sizeof(int)); #endif + } + if (pvio->timeout[PVIO_READ_TIMEOUT] > 0) + { +#ifndef _WIN32 + tm.tv_sec= pvio->timeout[PVIO_READ_TIMEOUT] / 1000; + tm.tv_usec= pvio->timeout[PVIO_READ_TIMEOUT] % 1000; + setsockopt(csock->socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tm, sizeof(tm)); +#else + setsockopt(csock->socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&pvio->timeout[PVIO_WRITE_TIMEOUT], sizeof(int)); +#endif + } return 0; error: if (pvio->data) diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index 56153a5e..d30c7b48 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -973,6 +973,24 @@ static int test_conc117(MYSQL *mysql) return OK; } +static int test_read_timeout(MYSQL *mysql) +{ + int timeout= 5, rc; + MYSQL *my= mysql_init(NULL); + mysql_options(my, MYSQL_OPT_READ_TIMEOUT, &timeout); + FAIL_IF(!mysql_real_connect(my, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + rc= mysql_query(my, "SELECT SLEEP(50)"); + + FAIL_IF(rc == 0, "error expected"); + diag("error: %s", mysql_error(my)); + + mysql_close(my); + + return OK; +} + #ifdef HAVE_REMOTEIO void *remote_plugin; static int test_remote1(MYSQL *mysql) @@ -1113,6 +1131,7 @@ static int test_zerofill(MYSQL *mysql) } struct my_tests_st my_tests[] = { + {"test_read_timeout", test_read_timeout, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_zerofill", test_zerofill, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, #ifdef HAVE_REMOTEIO {"test_remote1", test_remote1, TEST_CONNECTION_NEW, 0, NULL, NULL},