From: | Scott Ribe <scott_ribe(at)killerbytes(dot)com> |
---|---|
To: | Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> |
Cc: | PG-General Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Cheapest way to poll for notifications? |
Date: | 2009-12-10 23:20:28 |
Message-ID: | C746D04C.CAE15%scott_ribe@killerbytes.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-jdbc |
> Right?
Right. The way I do it, very roughly:
Pqconnectdb(...)
PQexec( mDbConn, "listen notify" );
int dbsock = PQsocket( mDbConn );
mKq = kqueue();
struct kevent kev[1], kevs[1];
EV_SET( &kev[0], dbsock, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0 );
kevent( mKq, kev, 1, NULL, 0, NULL );
while( true ) {
bool needsnotify = false;
int evtcnt = kevent( mKq, NULL, 0, kevs, 1, NULL );
if( evtcnt == 1 && kevs[i].filter == EVFILT_READ && kevs[i].ident ==
dbsock ) {
while( true ) {
PQconsumeInput( mDbConn );
PGnotify * notify = PQnotifies( mDbConn );
if( notify ) {
free( notify );
needsnotify = true;
}
else
break;
}
}
if( needsnotify )
// go off & query the db & handle updates here
}
Of course you could also use select to wait on the socket.
--
Scott Ribe
scott_ribe(at)killerbytes(dot)com
http://www.killerbytes.com/
(303) 722-0567 voice
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-12-10 23:28:56 | Re: Postgres "locked up" |
Previous Message | Tom Lane | 2009-12-10 23:04:38 | Re: Seeking expected return type info for SPI function |
From | Date | Subject | |
---|---|---|---|
Next Message | John R Pierce | 2009-12-11 00:19:49 | Re: Connection.setReadOnly() |
Previous Message | Kris Jurka | 2009-12-10 22:45:12 | Re: Connection.setReadOnly() |