On Thu, Dec 23, 2004 at 04:03:11PM -0800, Dan McCormick wrote:
> > I briefly considered whether the wheel should guarantee flushing on
> > shutdown, but I decided against it. Sometimes people may want to shut
> > down a client regardless of the input waiting for it.
> >
> > Maybe the shutdown methods need flush/immediate options?
>
> That would definitely be convenient. Would it be as simple as this? It
> works with the test case I sent earlier. I'll re-submit it with a doc patch
> if it looks ok.
>
> --- Run.pm Mon Nov 15 23:31:17 2004
> +++ Run.pm.new Thu Dec 23 15:28:09 2004
> @@ -859,8 +859,13 @@
>
> # Shutdown the pipe that leads to the child's STDIN.
> sub shutdown_stdin {
> - my $self = shift;
> + my ($self, %args) = @_;
> +
> return unless defined $self->[HANDLE_STDIN];
> +
> + if ($args{flush}) {
> + $self->[DRIVER_STDIN]->flush($self->[HANDLE_STDIN]);
> + }
>
> $poe_kernel->select_write($self->[HANDLE_STDIN], undef);
>
> Dan
Your patch will work in a lot of cases, but it won't work in all of
them. Consider when flush() is called to write to a full pipe. It
can't block, so it must return while the driver's buffer contains
data.
A more complete solution would be to check the driver's output buffer
after flush(). If it flushed everything, go ahead and shutdown right
away. Otherwise set a flag in the wheel, and check it after the usual
flush().
--
Rocco Caputo - http://poe.perl.org/