diff options
author | Alvaro Herrera | 2021-06-29 18:37:39 +0000 |
---|---|---|
committer | Alvaro Herrera | 2021-06-29 18:37:39 +0000 |
commit | a7192326c74da417d024a189da4d33c1bf1b40b6 (patch) | |
tree | 1f568478bd54d354736330effbe2f94faa566d49 /src/interfaces/libpq/fe-exec.c | |
parent | dd2364ced98553e0217bfe8f621cd4b0970db74a (diff) |
Add PQsendFlushRequest to libpq
This new libpq function allows the application to send an 'H' message,
which instructs the server to flush its outgoing buffer.
This hasn't been needed so far because the Sync message already requests
a buffer; and I failed to realize that this was needed in pipeline mode
because PQpipelineSync also causes the buffer to be flushed. However,
sometimes it is useful to request a flush without establishing a
synchronization point.
Backpatch to 14, where pipeline mode was introduced in libpq.
Reported-by: Boris Kolpackov <boris@codesynthesis.com>
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/202106252350.t76x73nt643j@alvherre.pgsql
Diffstat (limited to 'src/interfaces/libpq/fe-exec.c')
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 7bd5b3a7b9d..c1b12696725 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -3099,6 +3099,42 @@ sendFailed: return 0; } +/* + * PQsendFlushRequest + * Send request for server to flush its buffer. Useful in pipeline + * mode when a sync point is not desired. + */ +int +PQsendFlushRequest(PGconn *conn) +{ + if (!conn) + return 0; + + /* Don't try to send if we know there's no live connection. */ + if (conn->status != CONNECTION_OK) + { + appendPQExpBufferStr(&conn->errorMessage, + libpq_gettext("no connection to the server\n")); + return 0; + } + + /* Can't send while already busy, either, unless enqueuing for later */ + if (conn->asyncStatus != PGASYNC_IDLE && + conn->pipelineStatus == PQ_PIPELINE_OFF) + { + appendPQExpBufferStr(&conn->errorMessage, + libpq_gettext("another command is already in progress\n")); + return false; + } + + if (pqPutMsgStart('H', conn) < 0 || + pqPutMsgEnd(conn) < 0) + { + return 0; + } + + return 1; +} /* ====== accessor funcs for PGresult ======== */ |