* parseInput: if appropriate, parse input data from backend * until input is exhausted or a stopping state is reached. * Note that this function will NOT attempt to read more data from the backend. */
| 76 | * Note that this function will NOT attempt to read more data from the backend. |
| 77 | */ |
| 78 | void |
| 79 | pqParseInput3(PGconn *conn) |
| 80 | { |
| 81 | char id; |
| 82 | int msgLength; |
| 83 | int avail; |
| 84 | #ifndef FRONTEND |
| 85 | int i; |
| 86 | int64 numRejected = 0; |
| 87 | int64 numCompleted = 0; |
| 88 | #endif |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * Loop to parse successive complete messages available in the buffer. |
| 93 | */ |
| 94 | for (;;) |
| 95 | { |
| 96 | /* |
| 97 | * Try to read a message. First get the type code and length. Return |
| 98 | * if not enough data. |
| 99 | */ |
| 100 | conn->inCursor = conn->inStart; |
| 101 | if (pqGetc(&id, conn)) |
| 102 | return; |
| 103 | if (pqGetInt(&msgLength, 4, conn)) |
| 104 | return; |
| 105 | |
| 106 | /* |
| 107 | * Try to validate message type/length here. A length less than 4 is |
| 108 | * definitely broken. Large lengths should only be believed for a few |
| 109 | * message types. |
| 110 | */ |
| 111 | if (msgLength < 4) |
| 112 | { |
| 113 | handleSyncLoss(conn, id, msgLength); |
| 114 | return; |
| 115 | } |
| 116 | if (msgLength > 30000 && !VALID_LONG_MESSAGE_TYPE(id)) |
| 117 | { |
| 118 | handleSyncLoss(conn, id, msgLength); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Can't process if message body isn't all here yet. |
| 124 | */ |
| 125 | msgLength -= 4; |
| 126 | avail = conn->inEnd - conn->inCursor; |
| 127 | if (avail < msgLength) |
| 128 | { |
| 129 | /* |
| 130 | * Before returning, enlarge the input buffer if needed to hold |
| 131 | * the whole message. This is better than leaving it to |
| 132 | * pqReadData because we can avoid multiple cycles of realloc() |
| 133 | * when the message is large; also, we can implement a reasonable |
| 134 | * recovery strategy if we are unable to make the buffer big |
| 135 | * enough. |
no test coverage detected