---------------- * 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
| 2319 | * ---------------- |
| 2320 | */ |
| 2321 | PostgresPollingStatusType |
| 2322 | PQconnectPoll(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; |
no test coverage detected