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

Function PQconnectPoll

src/interfaces/libpq/fe-connect.c:2321–3965  ·  view source on GitHub ↗

---------------- * PQconnectPoll * * Poll an asynchronous connection. * * Returns a PostgresPollingStatusType. * Before calling this function, use select(2) to determine when data * has arrived.. * * You must call PQfinish whether or not this fails. * * This function and PQconnectStart are intended to allow connections to be * made without blocking the execution of your program on rem

Source from the content-addressed store, hash-verified

2319 * ----------------
2320 */
2321PostgresPollingStatusType
2322PQconnectPoll(PGconn *conn)
2323{
2324 bool reset_connection_state_machine = false;
2325 bool need_new_connection = false;
2326 PGresult *res;
2327 char sebuf[PG_STRERROR_R_BUFLEN];
2328 int optval;
2329
2330 if (conn == NULL)
2331 return PGRES_POLLING_FAILED;
2332
2333 /* Get the new data */
2334 switch (conn->status)
2335 {
2336 /*
2337 * We really shouldn't have been polled in these two cases, but we
2338 * can handle it.
2339 */
2340 case CONNECTION_BAD:
2341 return PGRES_POLLING_FAILED;
2342 case CONNECTION_OK:
2343 return PGRES_POLLING_OK;
2344
2345 /* These are reading states */
2346 case CONNECTION_AWAITING_RESPONSE:
2347 case CONNECTION_AUTH_OK:
2348 case CONNECTION_CHECK_WRITABLE:
2349 case CONNECTION_CONSUME:
2350 case CONNECTION_CHECK_STANDBY:
2351 {
2352 /* Load waiting data */
2353 int n = pqReadData(conn);
2354
2355 if (n < 0)
2356 goto error_return;
2357 if (n == 0)
2358 return PGRES_POLLING_READING;
2359
2360 break;
2361 }
2362
2363 /* These are writing states, so we just proceed. */
2364 case CONNECTION_STARTED:
2365 case CONNECTION_MADE:
2366 break;
2367
2368 /* Special cases: proceed without waiting. */
2369 case CONNECTION_SSL_STARTUP:
2370 case CONNECTION_NEEDED:
2371 case CONNECTION_GSS_STARTUP:
2372 case CONNECTION_CHECK_TARGET:
2373 break;
2374
2375 default:
2376 appendPQExpBufferStr(&conn->errorMessage,
2377 libpq_gettext("invalid connection state, probably indicative of memory corruption\n"));
2378 goto error_return;

Callers 8

ftsConnectFunction · 0.85
ManageCronTaskFunction · 0.85
libpqrcv_connectFunction · 0.85
cdbgang_createGang_asyncFunction · 0.85
connectDBStartFunction · 0.85
connectDBCompleteFunction · 0.85
PQresetPollFunction · 0.85
ftsConnectFunction · 0.85

Calls 15

pqReadDataFunction · 0.85
appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
release_conn_addrinfoFunction · 0.85
parse_int_paramFunction · 0.85
appendPQExpBufferFunction · 0.85
pg_getaddrinfo_allFunction · 0.85
gai_strerrorFunction · 0.85
pqDropConnectionFunction · 0.85
pqDropServerDataFunction · 0.85
pqClearAsyncResultFunction · 0.85
getHostaddrFunction · 0.85

Tested by

no test coverage detected