mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 02:54:29 +08:00
Merge pull request #26 from chipturner/master
Extend read_timeout support to also include write_timeouts
This commit is contained in:
22
_mysql.c
22
_mysql.c
@ -121,7 +121,7 @@ static int _mysql_server_init_done = 0;
|
||||
/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
|
||||
The MYSQL_OPT_READ_TIMEOUT apear in the version 5.1.12 */
|
||||
#if MYSQL_VERSION_ID > 50112
|
||||
#define HAVE_MYSQL_OPT_READ_TIMEOUT 1
|
||||
#define HAVE_MYSQL_OPT_TIMEOUTS 1
|
||||
#endif
|
||||
|
||||
PyObject *
|
||||
@ -566,13 +566,15 @@ _mysql_ConnectionObject_Initialize(
|
||||
"read_default_file", "read_default_group",
|
||||
"client_flag", "ssl",
|
||||
"local_infile",
|
||||
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
|
||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||
"read_timeout",
|
||||
"write_timeout",
|
||||
#endif
|
||||
NULL } ;
|
||||
int connect_timeout = 0;
|
||||
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
|
||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||
int read_timeout = 0;
|
||||
int write_timeout = 0;
|
||||
#endif
|
||||
int compress = -1, named_pipe = -1, local_infile = -1;
|
||||
char *init_command=NULL,
|
||||
@ -584,8 +586,8 @@ _mysql_ConnectionObject_Initialize(
|
||||
check_server_init(-1);
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
|
||||
"|ssssisOiiisssiOii:connect",
|
||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||
"|ssssisOiiisssiOiii:connect",
|
||||
#else
|
||||
"|ssssisOiiisssiOi:connect",
|
||||
#endif
|
||||
@ -598,8 +600,9 @@ _mysql_ConnectionObject_Initialize(
|
||||
&read_default_group,
|
||||
&client_flag, &ssl,
|
||||
&local_infile
|
||||
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
|
||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||
, &read_timeout
|
||||
, &write_timeout
|
||||
#endif
|
||||
))
|
||||
return -1;
|
||||
@ -636,12 +639,17 @@ _mysql_ConnectionObject_Initialize(
|
||||
mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT,
|
||||
(char *)&timeout);
|
||||
}
|
||||
#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
|
||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||
if (read_timeout) {
|
||||
unsigned int timeout = read_timeout;
|
||||
mysql_options(&(self->connection), MYSQL_OPT_READ_TIMEOUT,
|
||||
(char *)&timeout);
|
||||
}
|
||||
if (write_timeout) {
|
||||
unsigned int timeout = write_timeout;
|
||||
mysql_options(&(self->connection), MYSQL_OPT_WRITE_TIMEOUT,
|
||||
(char *)&timeout);
|
||||
}
|
||||
#endif
|
||||
if (compress != -1) {
|
||||
mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0);
|
||||
|
Reference in New Issue
Block a user