This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fork problem


Hello,
	I slapped on some tools on my fork/Select problem and figured out
what was happening.

	If you need a refresher this is that calling socketpair and then
forking and then closing one end of the socket pair on the child doesn't
mean that the handle has been closed.  Basically after a fork you can have
open handles even if you close them.

	Basically when you call fork you create a new process, and inherit
all the handles.  Then fixup after fork calls DuplicateHandle to construct
the sockets.  So when you originally started with two handles for a socket
pair.  Your child process now has four.  (I detected this by using Process
Explorer from sysinternals)

	So my fix was to before calling the fork store away the handles
(using get_osfhandle) then after the fork the child process closes all the
handles using CloseHandle() of course there should be some better way of
doing this.  I don't think that WSASocket and Duplicate handle are
needed in fhandler_socket.  Since the handles are there I think you can
just set them properly.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]