mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 03:38:03 +08:00
Enable automatic reconnect in mysql (#1217)
Setting MYSQL_OPT_RECONNECT option to true will allow the connection to be restablished once before giving up and returning an error. This is useful in cases where the database is behind a loadbalancer (e.g. ipvs) and the tcp connection is terminated after some period of time.
This commit is contained in:
parent
567e7c07ad
commit
d51bae1016
@ -56,6 +56,7 @@ MysqlConnection::MysqlConnection(trantor::EventLoop *loop,
|
||||
{
|
||||
mysql_init(mysqlPtr_.get());
|
||||
mysql_options(mysqlPtr_.get(), MYSQL_OPT_NONBLOCK, nullptr);
|
||||
mysql_optionsv(mysqlPtr_.get(), MYSQL_OPT_RECONNECT, &reconnect_);
|
||||
|
||||
// Get the key and value
|
||||
auto connParams = parseConnString(connInfo);
|
||||
|
@ -110,6 +110,7 @@ class MysqlConnection : public DbConnection,
|
||||
void startQuery();
|
||||
void startStoreResult(bool queueInLoop);
|
||||
int waitStatus_;
|
||||
unsigned int reconnect_{1};
|
||||
enum class ExecStatus
|
||||
{
|
||||
None = 0,
|
||||
|
Loading…
Reference in New Issue
Block a user