|
@@ -51,7 +51,7 @@ typedef struct {
|
|
size_t query_num;
|
|
size_t query_num;
|
|
uint_fast32_t flags;
|
|
uint_fast32_t flags;
|
|
int sd;
|
|
int sd;
|
|
- h2o_timeout_entry_t timeout;
|
|
|
|
|
|
+ h2o_timer_t timer;
|
|
} db_conn_t;
|
|
} db_conn_t;
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
@@ -65,11 +65,11 @@ static int do_execute_query(db_conn_t *conn, db_query_param_t *param);
|
|
static void error_notification(db_conn_pool_t *pool, bool timeout, const char *error_string);
|
|
static void error_notification(db_conn_pool_t *pool, bool timeout, const char *error_string);
|
|
static void on_database_connect_error(db_conn_t *conn, bool timeout, const char *error_string);
|
|
static void on_database_connect_error(db_conn_t *conn, bool timeout, const char *error_string);
|
|
static void on_database_connect_read_ready(h2o_socket_t *sock, const char *err);
|
|
static void on_database_connect_read_ready(h2o_socket_t *sock, const char *err);
|
|
-static void on_database_connect_timeout(h2o_timeout_entry_t *entry);
|
|
|
|
|
|
+static void on_database_connect_timeout(h2o_timer_t *timer);
|
|
static void on_database_connect_write_ready(h2o_socket_t *sock, const char *err);
|
|
static void on_database_connect_write_ready(h2o_socket_t *sock, const char *err);
|
|
static void on_database_error(db_conn_t *conn, const char *error_string);
|
|
static void on_database_error(db_conn_t *conn, const char *error_string);
|
|
static void on_database_read_ready(h2o_socket_t *sock, const char *err);
|
|
static void on_database_read_ready(h2o_socket_t *sock, const char *err);
|
|
-static void on_database_timeout(h2o_timeout_entry_t *timeout);
|
|
|
|
|
|
+static void on_database_timeout(h2o_timer_t *timer);
|
|
static void on_database_write_ready(h2o_socket_t *sock, const char *err);
|
|
static void on_database_write_ready(h2o_socket_t *sock, const char *err);
|
|
static void poll_database_connection(h2o_socket_t *sock, const char *err);
|
|
static void poll_database_connection(h2o_socket_t *sock, const char *err);
|
|
static void prepare_statements(db_conn_t *conn);
|
|
static void prepare_statements(db_conn_t *conn);
|
|
@@ -147,9 +147,9 @@ static int do_execute_query(db_conn_t *conn, db_query_param_t *param)
|
|
h2o_socket_notify_write(conn->sock, on_database_write_ready);
|
|
h2o_socket_notify_write(conn->sock, on_database_write_ready);
|
|
|
|
|
|
if (!conn->queries.head && !(conn->flags & (EXPECT_SYNC | IGNORE_RESULT))) {
|
|
if (!conn->queries.head && !(conn->flags & (EXPECT_SYNC | IGNORE_RESULT))) {
|
|
- assert(!h2o_timeout_is_linked(&conn->timeout));
|
|
|
|
- conn->timeout.cb = on_database_timeout;
|
|
|
|
- h2o_timeout_link(conn->pool->loop, &conn->pool->timeout, &conn->timeout);
|
|
|
|
|
|
+ assert(!h2o_timer_is_linked(&conn->timer));
|
|
|
|
+ conn->timer.cb = on_database_timeout;
|
|
|
|
+ h2o_timer_link(conn->pool->loop, conn->pool->config->db_timeout * MS_IN_S, &conn->timer);
|
|
}
|
|
}
|
|
|
|
|
|
param->l.next = NULL;
|
|
param->l.next = NULL;
|
|
@@ -191,7 +191,7 @@ static void on_database_connect_error(db_conn_t *conn, bool timeout, const char
|
|
{
|
|
{
|
|
db_conn_pool_t * const pool = conn->pool;
|
|
db_conn_pool_t * const pool = conn->pool;
|
|
|
|
|
|
- h2o_timeout_unlink(&conn->timeout);
|
|
|
|
|
|
+ h2o_timer_unlink(&conn->timer);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_close(conn->sock);
|
|
h2o_socket_close(conn->sock);
|
|
PQfinish(conn->conn);
|
|
PQfinish(conn->conn);
|
|
@@ -236,7 +236,7 @@ static void on_database_connect_read_ready(h2o_socket_t *sock, const char *err)
|
|
break;
|
|
break;
|
|
case PGRES_PIPELINE_SYNC:
|
|
case PGRES_PIPELINE_SYNC:
|
|
PQclear(result);
|
|
PQclear(result);
|
|
- h2o_timeout_unlink(&conn->timeout);
|
|
|
|
|
|
+ h2o_timer_unlink(&conn->timer);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_read_start(conn->sock, on_database_read_ready);
|
|
h2o_socket_read_start(conn->sock, on_database_read_ready);
|
|
process_queries(conn);
|
|
process_queries(conn);
|
|
@@ -253,9 +253,9 @@ static void on_database_connect_read_ready(h2o_socket_t *sock, const char *err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void on_database_connect_timeout(h2o_timeout_entry_t *entry)
|
|
|
|
|
|
+static void on_database_connect_timeout(h2o_timer_t *timer)
|
|
{
|
|
{
|
|
- db_conn_t * const conn = H2O_STRUCT_FROM_MEMBER(db_conn_t, timeout, entry);
|
|
|
|
|
|
+ db_conn_t * const conn = H2O_STRUCT_FROM_MEMBER(db_conn_t, timer, timer);
|
|
|
|
|
|
ERROR(DB_TIMEOUT_ERROR);
|
|
ERROR(DB_TIMEOUT_ERROR);
|
|
on_database_connect_error(conn, true, DB_TIMEOUT_ERROR);
|
|
on_database_connect_error(conn, true, DB_TIMEOUT_ERROR);
|
|
@@ -356,9 +356,11 @@ static void on_database_read_ready(h2o_socket_t *sock, const char *err)
|
|
|
|
|
|
if (param->on_result(param, result) == DONE) {
|
|
if (param->on_result(param, result) == DONE) {
|
|
conn->query_num++;
|
|
conn->query_num++;
|
|
- h2o_timeout_unlink(&conn->timeout);
|
|
|
|
- conn->timeout.cb = on_database_timeout;
|
|
|
|
- h2o_timeout_link(conn->pool->loop, &conn->pool->timeout, &conn->timeout);
|
|
|
|
|
|
+ h2o_timer_unlink(&conn->timer);
|
|
|
|
+ conn->timer.cb = on_database_timeout;
|
|
|
|
+ h2o_timer_link(conn->pool->loop,
|
|
|
|
+ conn->pool->config->db_timeout * MS_IN_S,
|
|
|
|
+ &conn->timer);
|
|
conn->flags |= EXPECT_SYNC;
|
|
conn->flags |= EXPECT_SYNC;
|
|
conn->queries.head = next;
|
|
conn->queries.head = next;
|
|
|
|
|
|
@@ -373,7 +375,7 @@ static void on_database_read_ready(h2o_socket_t *sock, const char *err)
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
assert(!result);
|
|
assert(!result);
|
|
- h2o_timeout_unlink(&conn->timeout);
|
|
|
|
|
|
+ h2o_timer_unlink(&conn->timer);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -384,9 +386,9 @@ static void on_database_read_ready(h2o_socket_t *sock, const char *err)
|
|
process_queries(conn);
|
|
process_queries(conn);
|
|
}
|
|
}
|
|
|
|
|
|
-static void on_database_timeout(h2o_timeout_entry_t *timeout)
|
|
|
|
|
|
+static void on_database_timeout(h2o_timer_t *timer)
|
|
{
|
|
{
|
|
- db_conn_t * const conn = H2O_STRUCT_FROM_MEMBER(db_conn_t, timeout, timeout);
|
|
|
|
|
|
+ db_conn_t * const conn = H2O_STRUCT_FROM_MEMBER(db_conn_t, timer, timer);
|
|
|
|
|
|
ERROR(DB_TIMEOUT_ERROR);
|
|
ERROR(DB_TIMEOUT_ERROR);
|
|
|
|
|
|
@@ -456,7 +458,7 @@ static void poll_database_connection(h2o_socket_t *sock, const char *err)
|
|
|
|
|
|
return;
|
|
return;
|
|
case PGRES_POLLING_OK:
|
|
case PGRES_POLLING_OK:
|
|
- h2o_timeout_unlink(&conn->timeout);
|
|
|
|
|
|
+ h2o_timer_unlink(&conn->timer);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_read_stop(conn->sock);
|
|
|
|
|
|
if (PQsetnonblocking(conn->conn, 1)) {
|
|
if (PQsetnonblocking(conn->conn, 1)) {
|
|
@@ -532,8 +534,8 @@ static void prepare_statements(db_conn_t *conn)
|
|
}
|
|
}
|
|
|
|
|
|
conn->prepared_statement = NULL;
|
|
conn->prepared_statement = NULL;
|
|
- conn->timeout.cb = on_database_connect_timeout;
|
|
|
|
- h2o_timeout_link(conn->pool->loop, &conn->pool->timeout, &conn->timeout);
|
|
|
|
|
|
+ conn->timer.cb = on_database_connect_timeout;
|
|
|
|
+ h2o_timer_link(conn->pool->loop, conn->pool->config->db_timeout * MS_IN_S, &conn->timer);
|
|
h2o_socket_read_start(conn->sock, on_database_connect_read_ready);
|
|
h2o_socket_read_start(conn->sock, on_database_connect_read_ready);
|
|
on_database_connect_write_ready(conn->sock, NULL);
|
|
on_database_connect_write_ready(conn->sock, NULL);
|
|
}
|
|
}
|
|
@@ -579,7 +581,7 @@ static void start_database_connect(db_conn_pool_t *pool, db_conn_t *conn)
|
|
if (conn) {
|
|
if (conn) {
|
|
PGconn * const c = conn->conn;
|
|
PGconn * const c = conn->conn;
|
|
|
|
|
|
- h2o_timeout_unlink(&conn->timeout);
|
|
|
|
|
|
+ h2o_timer_unlink(&conn->timer);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_close(conn->sock);
|
|
h2o_socket_close(conn->sock);
|
|
|
|
|
|
@@ -620,8 +622,8 @@ static void start_database_connect(db_conn_pool_t *pool, db_conn_t *conn)
|
|
conn->prepared_statement = pool->prepared_statements;
|
|
conn->prepared_statement = pool->prepared_statements;
|
|
conn->queries.tail = &conn->queries.head;
|
|
conn->queries.tail = &conn->queries.head;
|
|
conn->query_num = pool->config->max_pipeline_query_num;
|
|
conn->query_num = pool->config->max_pipeline_query_num;
|
|
- conn->timeout.cb = on_database_connect_timeout;
|
|
|
|
- h2o_timeout_link(pool->loop, &pool->timeout, &conn->timeout);
|
|
|
|
|
|
+ conn->timer.cb = on_database_connect_timeout;
|
|
|
|
+ h2o_timer_link(pool->loop, pool->config->db_timeout * MS_IN_S, &conn->timer);
|
|
h2o_socket_notify_write(conn->sock, poll_database_connection);
|
|
h2o_socket_notify_write(conn->sock, poll_database_connection);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -697,7 +699,7 @@ void free_database_connection_pool(db_conn_pool_t *pool)
|
|
assert(conn->query_num == pool->config->max_pipeline_query_num);
|
|
assert(conn->query_num == pool->config->max_pipeline_query_num);
|
|
assert(conn->flags & IDLE);
|
|
assert(conn->flags & IDLE);
|
|
assert(!(conn->flags & (EXPECT_SYNC | IGNORE_RESULT | RESET)));
|
|
assert(!(conn->flags & (EXPECT_SYNC | IGNORE_RESULT | RESET)));
|
|
- assert(!h2o_timeout_is_linked(&conn->timeout));
|
|
|
|
|
|
+ assert(!h2o_timer_is_linked(&conn->timer));
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_read_stop(conn->sock);
|
|
h2o_socket_close(conn->sock);
|
|
h2o_socket_close(conn->sock);
|
|
PQfinish(conn->conn);
|
|
PQfinish(conn->conn);
|
|
@@ -707,7 +709,6 @@ void free_database_connection_pool(db_conn_pool_t *pool)
|
|
} while (pool->conn);
|
|
} while (pool->conn);
|
|
|
|
|
|
assert(num + pool->conn_num == pool->config->max_db_conn_num);
|
|
assert(num + pool->conn_num == pool->config->max_db_conn_num);
|
|
- h2o_timeout_dispose(pool->loop, &pool->timeout);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void initialize_database_connection_pool(const char *conninfo,
|
|
void initialize_database_connection_pool(const char *conninfo,
|
|
@@ -724,7 +725,6 @@ void initialize_database_connection_pool(const char *conninfo,
|
|
pool->queries.tail = &pool->queries.head;
|
|
pool->queries.tail = &pool->queries.head;
|
|
pool->conn_num = config->max_db_conn_num;
|
|
pool->conn_num = config->max_db_conn_num;
|
|
pool->query_num = config->max_query_num;
|
|
pool->query_num = config->max_query_num;
|
|
- h2o_timeout_init(loop, &pool->timeout, config->db_timeout * MS_IN_S);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void remove_prepared_statements(list_t *prepared_statements)
|
|
void remove_prepared_statements(list_t *prepared_statements)
|