#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "libpq-fe.h"


int main()
{
	PGconn *p = NULL;
	const char* keywords[] = { "host", "dbname", "user", "password", NULL };
	const char* values[] = { "localhost", "AAA", "gen", "GEN", NULL };

	p = PQconnectStartParams(keywords, values, 0);

	if (p == NULL) {
		printf("COULD NOT ALLOCATE MEMORY\n");
		exit(1);
	}
	else if (PQstatus(p) == CONNECTION_BAD) {
		printf("COULD NOT CONNECT\n");
		PQfinish(p);
		p = NULL;
	}

	PostgresPollingStatusType ps;

	ps = PQconnectPoll(p);
    while (ps != PGRES_POLLING_FAILED && ps != PGRES_POLLING_OK) {
        sleep(1);
        ps = PQconnectPoll(p);
        printf("open_connection_finalize[%d]\n", ps);
    }

	printf("DONE\n");

	return 0;
}
