Attached. -- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net
#!/usr/bin/perl
use warnings; use strict; # Enable DO_SHUTDOWN will make the sender call shutdown(SOCK,1). # This will cause a read error 0 on the receiver's side. sub DO_SHUTDOWN () { 0 } use POE; use POE::Wheel::ReadWrite; use POE::Pipe::OneWay; my $message = "this is the message"; POE::Session->create ( inline_states => { _start => sub { my ($r, $w) = POE::Pipe::OneWay->new("inet"); # Saving a copy of the write side of the pipe so shutdown() # can be called on it later. $_[HEAP]->{writer} = $w; $_[HEAP]->{wheel} = POE::Wheel::ReadWrite->new ( InputHandle => $r, OutputHandle => $w, InputEvent => "got_input", ErrorEvent => "got_error", FlushedEvent => "got_flush", ); $_[KERNEL]->delay(timed_out => 2); print "Writer sends a message: $message\n"; $_[HEAP]->{wheel}->put($message); }, # Writer flushed its message; it's safe to call shutdown() now. # There is no guarantee that put() will flush its data # immediately, so calling shutdown() early may cut off some # data. got_flush => sub { if (DO_SHUTDOWN) { print "Writer calls shutdown(SOCK,1).\n"; shutdown($_[HEAP]->{writer}, 1); } else { print "Writer does not shut down its side.\n"; } }, got_input => sub { print "Reader got input: $_[ARG0]\n"; }, got_error => sub { my $end = "Session got $_[ARG0]"; $end = 'Reader got' if $_[ARG0] eq 'read'; $end = 'Writer got' if $_[ARG0] eq 'write'; print "$end error $_[ARG1]: $_[ARG2]\n"; delete $_[HEAP]->{wheel}; $_[KERNEL]->delay(timed_out => undef); }, timed_out => sub { print "Session timed out.\n"; delete $_[HEAP]->{wheel}; }, }, ); $poe_kernel->run();