MCPcopy Create free account
hub / github.com/apache/cloudberry / pqReadData

Function pqReadData

src/interfaces/libpq/fe-misc.c:617–815  ·  view source on GitHub ↗

---------- * pqReadData: read more data, if any is available * Possible return values: * 1: successfully loaded at least one more byte * 0: no data is presently available, but no error detected * -1: error detected (including EOF = connection closure); * conn->errorMessage set * NOTE: callers must not assume that pointers or indexes into conn->inBuffer * remain valid across this call!

Source from the content-addressed store, hash-verified

615 * ----------
616 */
617int
618pqReadData(PGconn *conn)
619{
620 int someread = 0;
621 int nread;
622
623 if (conn->sock == PGINVALID_SOCKET)
624 {
625 appendPQExpBufferStr(&conn->errorMessage,
626 libpq_gettext("connection not open\n"));
627 return -1;
628 }
629
630 /* Left-justify any data in the buffer to make room */
631 if (conn->inStart < conn->inEnd)
632 {
633 if (conn->inStart > 0)
634 {
635 memmove(conn->inBuffer, conn->inBuffer + conn->inStart,
636 conn->inEnd - conn->inStart);
637 conn->inEnd -= conn->inStart;
638 conn->inCursor -= conn->inStart;
639 conn->inStart = 0;
640 }
641 }
642 else
643 {
644 /* buffer is logically empty, reset it */
645 conn->inStart = conn->inCursor = conn->inEnd = 0;
646 }
647
648 /*
649 * If the buffer is fairly full, enlarge it. We need to be able to enlarge
650 * the buffer in case a single message exceeds the initial buffer size. We
651 * enlarge before filling the buffer entirely so as to avoid asking the
652 * kernel for a partial packet. The magic constant here should be large
653 * enough for a TCP packet or Unix pipe bufferload. 8K is the usual pipe
654 * buffer size, so...
655 */
656 if (conn->inBufSize - conn->inEnd < 8192)
657 {
658 if (pqCheckInBufferSpace(conn->inEnd + (size_t) 8192, conn))
659 {
660 /*
661 * We don't insist that the enlarge worked, but we need some room
662 */
663 if (conn->inBufSize - conn->inEnd < 100)
664 return -1; /* errorMessage already set */
665 }
666 }
667
668 /* OK, try to read some data */
669retry3:
670 nread = pqsecure_read(conn, conn->inBuffer + conn->inEnd,
671 conn->inBufSize - conn->inEnd);
672 if (nread < 0)
673 {
674 switch (SOCK_ERRNO)

Callers 7

PQconnectPollFunction · 0.85
pqSendSomeFunction · 0.85
pqGetCopyData3Function · 0.85
pqGetline3Function · 0.85
pqFunctionCall3Function · 0.85
PQconsumeInputFunction · 0.85
PQgetResultFunction · 0.85

Calls 6

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
pqCheckInBufferSpaceFunction · 0.85
pqsecure_readFunction · 0.85
pqReadReadyFunction · 0.85
pqDropConnectionFunction · 0.85

Tested by

no test coverage detected