I would like to use the LISTEN and NOTIFY features of Postgres to implement
communication between to proceses connected to Postgres, but I don't want
to "listening" process to use polling to detect notifications. The
following polling example is given in the Postgres documentation:
while (1) { /* * wait a little bit between checks; waiting with select() * would be more
efficient. */ sleep(1); /* collect any asynchronous backend messages */ PQconsumeInput(conn);
/* check for asynchronous notify messages */ while ((notify = PQnotifies(conn)) != NULL) {
fprintf(stderr, "ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
notify->relname,notify->be_pid); free(notify); } }
Instead, I would rather use the "more efficient select(2)" method alluded
to in the Postgres documentation (and code above). Does anyone have
sample code that uses this method to wait for a backend notification to
arrive?
Thanks in advance...
Steven Bradley
Lawrence Livermore National Laboratory
sbradley@llnl.gov