2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/util/db-mysql.h"
22 ///////////////////////////////////////////////////////////////////////////////
24 int MySQLUtil::set_mysql_timeout(MYSQL
*mysql
, MySQLUtil::TimeoutType type
, int ms
) {
25 mysql_option opt
= MYSQL_OPT_CONNECT_TIMEOUT
;
26 #ifdef MYSQL_MILLISECOND_TIMEOUT
28 case MySQLUtil::ConnectTimeout
: opt
= MYSQL_OPT_CONNECT_TIMEOUT_MS
; break;
29 case MySQLUtil::ReadTimeout
: opt
= MYSQL_OPT_READ_TIMEOUT_MS
; break;
30 case MySQLUtil::WriteTimeout
: opt
= MYSQL_OPT_WRITE_TIMEOUT_MS
; break;
31 default: assert(false); break;
35 case MySQLUtil::ConnectTimeout
: opt
= MYSQL_OPT_CONNECT_TIMEOUT
; break;
36 case MySQLUtil::ReadTimeout
: opt
= MYSQL_OPT_READ_TIMEOUT
; break;
37 case MySQLUtil::WriteTimeout
: opt
= MYSQL_OPT_WRITE_TIMEOUT
; break;
38 default: assert(false); break;
40 ms
= (ms
+ 999) / 1000;
43 return mysql_options(mysql
, opt
, (const char*)&ms
);
46 ///////////////////////////////////////////////////////////////////////////////