Updated on 2024-06-03 GMT+08:00

PQflush

Description

Flushes any queued output data to the server.

Prototype

int PQflush(PGconn* conn);

Parameter

Table 1 PQflush parameter

Keyword

Description

conn

Points to the object pointer that contains the connection information.

Return Values

int indicates the execution result. If the operation is successful (or the send queue is empty), 0 is returned. If the operation fails, -1 is returned. If all data in the send queue fails to be sent, 1 is returned. (This case occurs only when the connection is non-blocking.) The failure cause is stored in conn->error_message.

Precautions

Call PQflush after sending any command or data over a non-blocking connection. If 1 is returned, wait for the socket to become read- or write-ready. If the socket becomes write-ready, call PQflush again. If the socket becomes read-ready, call PQconsumeInput and then call PQflush again. Repeat the operation until the value 0 is returned for PQflush. It is necessary to check read-ready and use PQconsumeInput to exhaust input because the server may prevent attempts to send data (such as NOTICE messages) to the client and does not read the client's data until the client reads its data. Once PQflush returns 0, wait for the socket to be read-ready and then read the response as described above.