Passing a PGconn * between two processes on Unix like systems
I two Unix/ process related questions:
Is there a documented way to pass around an (opened) PGconn * structure
between two processes on Unix?
When a process forks() and both the parent and child process continue to
use a previously opened PGconn * structure, is that behaviour defined?
Thanks,
Marc Balmer
On Thu, Jul 22, 2010 at 08:35, Marc Balmer <marc@msys.ch> wrote:
I two Unix/ process related questions:
Is there a documented way to pass around an (opened) PGconn * structure
between two processes on Unix?
No.
You can probably hack up something yourself but you'd have to look
inside the struct which is not part of the public API - so it'd be a
very version-dependent (even minor-version dependent!) hack.
When a process forks() and both the parent and child process continue to
use a previously opened PGconn * structure, is that behaviour defined?
Yes - "broken" :-)
Well, the child can continue to use it *as long as the parent doesn't
use it anymore*.
And note that while it may be a good idea in general to close the
socket in the parent, you can *not* call PQclose() on it - that'll
tell the server you're disconnecting, and the child will stop working.
In theory you could do something like close(PQsocket(conn))...
--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/
On 22 Jul 2010, at 8:35, Marc Balmer wrote:
When a process forks() and both the parent and child process continue to
use a previously opened PGconn * structure, is that behaviour defined?
I recall having done this successfully, but you have to take care to synchronise access to the connection. You can't have multiple transactions running in parallel on one connection.
Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.
!DSPAM:737,4c482748286211410335719!