Mercurial > dovecot > core-2.2
changeset 19319:5288c66c7d69
mysql: Use the correct way of setting a connect timeout.
I'm not sure if this didn't exist earlier, or if I just somehow missed it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Oct 2015 16:56:23 +0300 |
parents | f9a143c630a5 |
children | e9f5db1e5770 |
files | src/lib-sql/driver-mysql.c |
diffstat | 1 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-sql/driver-mysql.c Tue Oct 20 15:29:07 2015 +0300 +++ b/src/lib-sql/driver-mysql.c Tue Oct 20 16:56:23 2015 +0300 @@ -76,7 +76,8 @@ struct mysql_db *db = (struct mysql_db *)_db; const char *unix_socket, *host; unsigned long client_flags = db->client_flags; - unsigned int secs_used; + unsigned int secs_used, connect_timeout = SQL_CONNECT_TIMEOUT_SECS; + time_t start_time; bool failed; i_assert(db->api.state == SQL_DB_STATE_DISCONNECTED); @@ -96,6 +97,7 @@ db->option_file); } + mysql_options(db->mysql, MYSQL_OPT_CONNECT_TIMEOUT, &connect_timeout); mysql_options(db->mysql, MYSQL_READ_DEFAULT_GROUP, db->option_group != NULL ? db->option_group : "client"); @@ -118,15 +120,15 @@ #endif } - alarm(SQL_CONNECT_TIMEOUT_SECS); #ifdef CLIENT_MULTI_RESULTS client_flags |= CLIENT_MULTI_RESULTS; #endif /* CLIENT_MULTI_RESULTS allows the use of stored procedures */ + start_time = time(NULL); failed = mysql_real_connect(db->mysql, host, db->user, db->password, db->dbname, db->port, unix_socket, client_flags) == NULL; - secs_used = SQL_CONNECT_TIMEOUT_SECS - alarm(0); + secs_used = time(NULL) - start_time; if (failed) { /* connecting could have taken a while. make sure that any timeouts that get added soon will get a refreshed