kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 4893a030a6819078d246646f50bfd46650d00620
parent ae4201c64769d200b7a62bffee664d56274be52f
Author: Joris Vink <joris@coders.se>
Date:   Mon, 21 Aug 2017 14:25:09 +0200

small pgsql fixes.

- make sure conn_count per pgsqldb structure is initialized to 0.
- allow pgsql_conn_max to be 0, meaning just create a new connection
  if none was free.

Diffstat:
includes/pgsql.h | 4++--
src/pgsql.c | 10++++++----
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/includes/pgsql.h b/includes/pgsql.h @@ -43,8 +43,8 @@ struct pgsql_conn { struct pgsql_db { char *name; char *conn_string; - u_int16_t pgsql_conn_max; - u_int16_t pgsql_conn_count; + u_int16_t conn_max; + u_int16_t conn_count; LIST_ENTRY(pgsql_db) rlist; }; diff --git a/src/pgsql.c b/src/pgsql.c @@ -289,7 +289,8 @@ kore_pgsql_register(const char *dbname, const char *connstring) pgsqldb = kore_malloc(sizeof(*pgsqldb)); pgsqldb->name = kore_strdup(dbname); - pgsqldb->pgsql_conn_max = pgsql_conn_max; + pgsqldb->conn_count = 0; + pgsqldb->conn_max = pgsql_conn_max; pgsqldb->conn_string = kore_strdup(connstring); LIST_INSERT_HEAD(&pgsql_db_conn_strings, pgsqldb, rlist); @@ -474,7 +475,8 @@ rescan: } if (conn == NULL) { - if (db->pgsql_conn_count >= db->pgsql_conn_max) { + if (db->conn_max != 0 && + db->conn_count >= db->conn_max) { if (pgsql->flags & KORE_PGSQL_ASYNC) { pgsql_queue_add(pgsql); } else { @@ -593,7 +595,7 @@ pgsql_conn_create(struct kore_pgsql *pgsql, struct pgsql_db *db) if (db == NULL || db->conn_string == NULL) fatal("pgsql_conn_create: no connection string"); - db->pgsql_conn_count++; + db->conn_count++; conn = kore_malloc(sizeof(*conn)); conn->job = NULL; @@ -681,7 +683,7 @@ pgsql_conn_cleanup(struct pgsql_conn *conn) LIST_FOREACH(pgsqldb, &pgsql_db_conn_strings, rlist) { if (strcmp(pgsqldb->name, conn->name)) { - pgsqldb->pgsql_conn_count--; + pgsqldb->conn_count--; break; } }