contrib/postgres_fdw/connection.c
PGresult *
pgfdw_get_result(PGconn *conn, const char *query)
{
	PGresult   *last_res = NULL;

	for (;;)
	{
		PGresult   *res;

		while (PQisBusy(conn))
		{
			int			wc;

			/* Sleep until there's something to do */
			wc = WaitLatchOrSocket(MyLatch,
								   WL_LATCH_SET | WL_SOCKET_READABLE,
								   PQsocket(conn),
								   -1L, PG_WAIT_EXTENSION);
			ResetLatch(MyLatch);

			CHECK_FOR_INTERRUPTS();

			/* Data available in socket */
			if (wc & WL_SOCKET_READABLE)
			{
				if (!PQconsumeInput(conn))
					pgfdw_report_error(ERROR, NULL, conn, false, query);
			}
		}

		res = PQgetResult(conn);
		if (res == NULL)
			break;				/* query is complete */

		PQclear(last_res);
		last_res = res;
	}

	return last_res;
}
/*
 * Wait for the result from a prior asynchronous execution function call.
 *
 * This function offers quick responsiveness by checking for any interruptions.
 *
 * This function emulates the PQexec()'s behavior of returning the last result
 * when there are many.
 *
 * Caller is responsible for the error handling on the result.
 */
Wait for the result from a prior asynchronous execution function call.
This function offers quick responsiveness by checking for any interruptions.

This function emulates the PQexec()'s behavior of returning the last result
when there are many.

Caller is responsible for the error handling on the result.
Wait for the result from a prior asynchronous execution function call . This function offers quick responsiveness by checking for any interruptions . This function emulates the PQexec () ' s behavior of returning the last result when there are many . Caller is responsible for the error handling on the result .
PGresult *
pgfdw_get_result(PGconn *conn, const char *query)
{
	PGresult   *last_res = NULL;
	for (;;)
	{
		PGresult   *res;
		while (PQisBusy(conn))
		{
			int			wc;
			wc = WaitLatchOrSocket(MyLatch,
								   WL_LATCH_SET | WL_SOCKET_READABLE,
								   PQsocket(conn),
								   -1L, PG_WAIT_EXTENSION);
			ResetLatch(MyLatch);
			CHECK_FOR_INTERRUPTS();
			if (wc & WL_SOCKET_READABLE)
			{
				if (!PQconsumeInput(conn))
					pgfdw_report_error(ERROR, NULL, conn, false, query);
			}
		}
		res = PQgetResult(conn);
		if (res == NULL)
			break;				
		PQclear(last_res);
		last_res = res;
	}
	return last_res;
}
PGresult * pgfdw_get_result ( PGconn * conn , const char * query ) { PGresult * last_res = NULL ; for ( ; ; ) { PGresult * res ; while ( PQisBusy ( conn ) ) { int wc ; wc = WaitLatchOrSocket ( MyLatch , WL_LATCH_SET | WL_SOCKET_READABLE , PQsocket ( conn ) , -1L , PG_WAIT_EXTENSION ) ; ResetLatch ( MyLatch ) ; CHECK_FOR_INTERRUPTS ( ) ; if ( wc & WL_SOCKET_READABLE ) { if ( ! PQconsumeInput ( conn ) ) pgfdw_report_error ( ERROR , NULL , conn , false , query ) ; } } res = PQgetResult ( conn ) ; if ( res == NULL ) break ; PQclear ( last_res ) ; last_res = res ; } return last_res ; }
Wait for the result from a prior asynchronous execution function call.
Wait for the result from a prior asynchronous execution function call .
/* Sleep until there's something to do */ /* Data available in socket */ /* query is complete */