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 c25c1c528176c21e0dbcb3637d4e89124e208005
parent 09b0ae6d425d11727802f05258a16dd0dfa18181
Author: Joris Vink <joris@coders.se>
Date:   Mon,  6 Feb 2017 20:01:16 +0100

pgsql: don't do a PQcancel() if it's not needed.

Diffstat:
src/pgsql.c | 25++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/pgsql.c b/src/pgsql.c @@ -41,6 +41,7 @@ struct pgsql_wait { #define PGSQL_LIST_INSERTED 0x0100 static void pgsql_queue_wakeup(void); +static void pgsql_cancel(struct kore_pgsql *); static void pgsql_set_error(struct kore_pgsql *, const char *); static void pgsql_queue_add(struct http_request *); static void pgsql_conn_release(struct kore_pgsql *); @@ -527,8 +528,6 @@ static void pgsql_conn_release(struct kore_pgsql *pgsql) { int fd; - PGcancel *cancel; - char buf[256]; if (pgsql->conn == NULL) return; @@ -539,13 +538,8 @@ pgsql_conn_release(struct kore_pgsql *pgsql) fd = PQsocket(pgsql->conn->db); kore_platform_disable_read(fd); - if ((cancel = PQgetCancel(pgsql->conn->db)) != NULL) { - if (!PQcancel(cancel, buf, sizeof(buf))) { - kore_log(LOG_ERR, - "failed to cancel: %s", buf); - } - PQfreeCancel(cancel); - } + if (pgsql->state != KORE_PGSQL_STATE_DONE) + pgsql_cancel(pgsql); } kore_pool_put(&pgsql_job_pool, pgsql->conn->job); } @@ -631,3 +625,16 @@ pgsql_read_result(struct kore_pgsql *pgsql) break; } } + +static void +pgsql_cancel(struct kore_pgsql *pgsql) +{ + PGcancel *cancel; + char buf[256]; + + if ((cancel = PQgetCancel(pgsql->conn->db)) != NULL) { + if (!PQcancel(cancel, buf, sizeof(buf))) + kore_log(LOG_ERR, "failed to cancel: %s", buf); + PQfreeCancel(cancel); + } +}