Recent

Author Topic: fpSelect and database (PostgreSQL) connections  (Read 747 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
fpSelect and database (PostgreSQL) connections
« 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: fpSelect and database (PostgreSQL) connections
« Reply #1 on: July 10, 2020, 11:24:35 am »
(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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: fpSelect and database (PostgreSQL) connections
« Reply #2 on: July 10, 2020, 12:06:13 pm »
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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018