mirror of
https://github.com/jorisvink/kore
synced 2025-03-10 04:59:02 -04:00
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.
This commit is contained in:
parent
ae4201c647
commit
4893a030a6
@ -43,8 +43,8 @@ struct pgsql_conn {
|
|||||||
struct pgsql_db {
|
struct pgsql_db {
|
||||||
char *name;
|
char *name;
|
||||||
char *conn_string;
|
char *conn_string;
|
||||||
u_int16_t pgsql_conn_max;
|
u_int16_t conn_max;
|
||||||
u_int16_t pgsql_conn_count;
|
u_int16_t conn_count;
|
||||||
|
|
||||||
LIST_ENTRY(pgsql_db) rlist;
|
LIST_ENTRY(pgsql_db) rlist;
|
||||||
};
|
};
|
||||||
|
10
src/pgsql.c
10
src/pgsql.c
@ -289,7 +289,8 @@ kore_pgsql_register(const char *dbname, const char *connstring)
|
|||||||
|
|
||||||
pgsqldb = kore_malloc(sizeof(*pgsqldb));
|
pgsqldb = kore_malloc(sizeof(*pgsqldb));
|
||||||
pgsqldb->name = kore_strdup(dbname);
|
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);
|
pgsqldb->conn_string = kore_strdup(connstring);
|
||||||
LIST_INSERT_HEAD(&pgsql_db_conn_strings, pgsqldb, rlist);
|
LIST_INSERT_HEAD(&pgsql_db_conn_strings, pgsqldb, rlist);
|
||||||
|
|
||||||
@ -474,7 +475,8 @@ rescan:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conn == NULL) {
|
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) {
|
if (pgsql->flags & KORE_PGSQL_ASYNC) {
|
||||||
pgsql_queue_add(pgsql);
|
pgsql_queue_add(pgsql);
|
||||||
} else {
|
} else {
|
||||||
@ -593,7 +595,7 @@ pgsql_conn_create(struct kore_pgsql *pgsql, struct pgsql_db *db)
|
|||||||
if (db == NULL || db->conn_string == NULL)
|
if (db == NULL || db->conn_string == NULL)
|
||||||
fatal("pgsql_conn_create: no connection string");
|
fatal("pgsql_conn_create: no connection string");
|
||||||
|
|
||||||
db->pgsql_conn_count++;
|
db->conn_count++;
|
||||||
|
|
||||||
conn = kore_malloc(sizeof(*conn));
|
conn = kore_malloc(sizeof(*conn));
|
||||||
conn->job = NULL;
|
conn->job = NULL;
|
||||||
@ -681,7 +683,7 @@ pgsql_conn_cleanup(struct pgsql_conn *conn)
|
|||||||
|
|
||||||
LIST_FOREACH(pgsqldb, &pgsql_db_conn_strings, rlist) {
|
LIST_FOREACH(pgsqldb, &pgsql_db_conn_strings, rlist) {
|
||||||
if (strcmp(pgsqldb->name, conn->name)) {
|
if (strcmp(pgsqldb->name, conn->name)) {
|
||||||
pgsqldb->pgsql_conn_count--;
|
pgsqldb->conn_count--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user