On 2021-Jun-25, Alvaro Herrera wrote:

> From 071757645ee0f9f15f57e43447d7c234deb062c0 Mon Sep 17 00:00:00 2001
> From: Alvaro Herrera <alvhe...@alvh.no-ip.org>
> Date: Fri, 25 Jun 2021 16:02:00 -0400
> Subject: [PATCH v2 2/4] Add PQrequestFlush()

I forgot to mention:

> +/*
> + * Send request for server to flush its buffer
> + */
> +int
> +PQrequestFlush(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;
> +     }
> +     /* XXX useless without a flush ...? */
> +     pqFlush(conn);
> +
> +     return 1;
> +}

I'm not sure if it's a good idea for PQrequestFlush to itself flush
libpq's buffer.  We can just document that PQflush is required ...
opinions?

(I didn't try PQrequestFlush in any scenarios other than the test case I
added.)

-- 
Álvaro Herrera       Valdivia, Chile
Voy a acabar con todos los humanos / con los humanos yo acabaré
voy a acabar con todos (bis) / con todos los humanos acabaré ¡acabaré! (Bender)


Reply via email to