Search Postgresql Archives

Re: Cheapest way to poll for notifications?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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@xxxxxxxxxxxxxxx
http://www.killerbytes.com/
(303) 722-0567 voice



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux