/* * pqPutMsgEnd: finish constructing a message and possibly send it * * Returns 0 on success, EOF on error * * We don't actually send anything here unless we've accumulated at least * 8K worth of data (the typical size of a pipe buffer on Unix systems). * This avoids sending small partial packets. The caller must use pqFlush * when it's important to flush all the data out to the server. */ int pqPutMsgEnd(PGconn *conn) { if (conn->Pfdebug) fprintf(conn->Pfdebug, "To backend> Msg complete, length %u\n", conn->outMsgEnd - conn->outCount); /* Fill in length word if needed */ if (conn->outMsgStart >= 0) { uint32 msgLen = conn->outMsgEnd - conn->outMsgStart; msgLen = htonl(msgLen); memcpy(conn->outBuffer + conn->outMsgStart, &msgLen, 4); } /* Make message eligible to send */ conn->outCount = conn->outMsgEnd; if (conn->outCount >= 8192) { int toSend = conn->outCount - (conn->outCount % 8192); if (pqSendSome(conn, toSend) < 0) return EOF; /* in nonblock mode, don't complain if unable to send it all */ } return 0; }
/* * pqFlush: send any data waiting in the output buffer * * Return 0 on success, -1 on failure and 1 when not all data could be sent * because the socket would block and the connection is non-blocking. */ int pqFlush(PGconn *conn) { if (conn->Pfdebug) fflush(conn->Pfdebug); if (conn->outCount > 0) return pqSendSome(conn, conn->outCount); return 0; }
/* * pqPutMsgEnd: finish constructing a message and possibly send it * * Returns 0 on success, EOF on error * * We don't actually send anything here unless we've accumulated at least * 8K worth of data (the typical size of a pipe buffer on Unix systems). * This avoids sending small partial packets. The caller must use pqFlush * when it's important to flush all the data out to the server. */ int pqPutMsgEnd(PGconn *conn) { pqPutMsgEndNoAutoFlush(conn); if (conn->outCount >= 8192) { int toSend = conn->outCount - (conn->outCount % 8192); if (pqSendSome(conn, toSend) < 0) return EOF; /* in nonblock mode, don't complain if unable to send it all */ } return 0; }