How about this for passing file descriptors?
Sat Jul 13 12:50:00 GMT 2002
I'm still thinking about this problem. Since my first solution
was shot down because of my use of the cygserver.
So here's a way to do it without the cygserver.
P1 wants to send FD1 to P2
#1 P1 calls sendmsg with Data
A. Extract handle from FD1, H1.
B. Duplicate H1 -> H1bis
C. Create an Event E1
D. Create header as follows:
HANDLE hDescriptor; = H1bis
HANDLEINFO hi; <--- This is obviously more.
HANDLE HEvent; = E1
E. Spawn a new thread to wait on event
i. When event is signalled close H1bis, then exit Thread.
F. Send header + Data
#2 P2 calls recvmsg
A. Get header + Data
B. Duplicate HEvent into current process -> E2
C. Duplicate hDescriptor into current process -> H2
D. Call SetEvent on E2
E. Turn H2 and HANDLEINFO into FD2
F. Return data and FD2
So this will work when the sender wants to close the FD after sending it.
Because a duplicate of the Handle is still hanging around in Duplicate
It will not work if the sender exits after sending it. Or rather there
will be a race condition. Is there a way to keep the process alive for a
little while? At least like 10 seconds or until the Event is signalled?
Note: If this message is confusing search for File Descriptor in
cygwin-patches where i posted a lot of info.
Let me know what you think,
More information about the Cygwin-developers