Lazarus
Programming => Databases => Topic started by: MarkMLl on July 10, 2020, 11:07:26 am
-
Is it possible to use fpSelect() on Linux etc. to monitor the handle associated with a database (Postgres, possibly Firebird) connection?
I've got fpSelect() with infinite timeout monitoring a couple of sockets: a (named) unix-domain socket and a (low-numbered) UDP socket. I'd like to also be able to monitor incoming database notification messages... I can obviously poll these possibly using a separate thread but I was wondering whether the existing code could be extended easily.
MarkMLl
-
(many databases employ a heartbeat system, not all traffic is actually notifications)
To answer the question: you could try, if you could get a handle for the socket. Never tried it myself.
-
True, but a heartbeat- assuming that it wasn't too fast- would still be a convenient way to break fpSelect() with an infinite timeout.
What I'll probably do as an ad-hoc solution is put say a 100 mSec timeout in the fpSelect(), and poll the underlying database library to see if there's a notification. Later on I'll investigate getting a handle.
This would have the advantage that it would give access to the message dispatch code which will be identical. If I had a second thread or relied on the Lazarus component (which didn't exist the last time I did this sort of thing) I'd probably have to start messing around with critical sections.
MarkMLl