summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Dustman <farcepest@gmail.com>2013-11-21 12:00:56 -0800
committerAndy Dustman <farcepest@gmail.com>2013-11-21 12:00:56 -0800
commitd236bb7f6b45f81f0156c4a0cfdef2319ba825d9 (patch)
tree50317599d76e73b241d0ae28628e89ef0c3dfc3f
parent002bbb8cd666577600338023f6fad149f105d106 (diff)
parent7e73533dd96da3fcd4c9eb3e9cff4a4dee19d8f0 (diff)
downloadmysqldb1-d236bb7f6b45f81f0156c4a0cfdef2319ba825d9.tar.gz
Merge pull request #26 from chipturner/master
Extend read_timeout support to also include write_timeouts
-rw-r--r--_mysql.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/_mysql.c b/_mysql.c
index 0fd7442..5b81c79 100644
--- a/_mysql.c
+++ b/_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);