--- AnyEvent-Fork/Fork.pm 2013/04/18 11:18:23 1.46 +++ AnyEvent-Fork/Fork.pm 2013/04/19 12:56:53 1.49 @@ -379,7 +379,7 @@ use IO::FDPass; -our $VERSION = 0.6; +our $VERSION = 0.7; # the early fork template process our $EARLY; @@ -450,7 +450,10 @@ undef $self->[WW]; # invoke run callback, if any - $self->[CB]->($self->[FH]) if $self->[CB]; + if ($self->[CB]) { + $self->[CB]->($self->[FH]); + @$self = (); + } }; () # make sure we don't leak the watcher @@ -773,6 +776,50 @@ $self->_cmd (r => $func); } +=item $proc->to_fh ($cb->($fh)) + +Flushes all commands out to the process and then calls the callback with +the communications socket. + +The process object becomes unusable on return from this function - any +further method calls result in undefined behaviour. + +The point of this method is to give you a file handle thta you cna pass +to another process. In that other process, you can call C to create a new C object from it, +thereby effectively passing a fork object to another process. + +=cut + +sub to_fh { + my ($self, $cb) = @_; + + $self->[CB] = $cb; + + unless ($self->[WW]) { + $self->[CB]->($self->[FH]); + @$self = (); + } +} + +=item new_from_fh AnyEvent::Fork $fh + +Takes a file handle originally rceeived by the C method and creates +a new C object. The child process itself will not change in +any way, i.e. it will keep all the modifications done to it before calling +C. + +The new object is very much like the original object, except that the +C method will return C even if the process is a direct child. + +=cut + +sub new_from_fh { + my ($class, $fh) = @_; + + $class->_new ($fh) +} + =back =head1 PERFORMANCE @@ -790,7 +837,7 @@ Then I did the same thing, but instead of calling fork, I called AnyEvent::Fork->new->run ("CORE::exit") and then again waited for the -socket form the child to close on exit. This does the same thing as manual +socket from the child to close on exit. This does the same thing as manual socket pair + fork, except that what is forked is the template process (2440kB), and the socket needs to be passed to the server at the other end of the socket first. @@ -907,8 +954,15 @@ useful that you can do with it without running into memory corruption issues or other braindamage. Hrrrr. +Since fork is endlessly broken on win32 perls (it doesn't even remotely +work within it's documented limits) and quite obviously it's not getting +improved any time soon, the best way to proceed on windows would be to +always use C and thus never rely on perl's fork "emulation". + Cygwin perl is not supported at the moment due to some hilarious -shortcomings of its API - see L for more details. +shortcomings of its API - see L for more details. If you never +use C and always use C to create processes, it should +work though. =head1 SEE ALSO