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

This commit is contained in:
Joris Vink 2017-02-06 20:01:16 +01:00
parent 09b0ae6d42
commit c25c1c5281
1 changed files with 16 additions and 9 deletions

View File

@ -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);
}
}