in reply to capturing syswrite failures

How about putting the syswrite in an unless block?
unless (syswrite($pc, $data)) { print STDERR $rc->peerhost,":",$rc->peerport, "<->",$pc->peerhost,":",$pc->peerport, " closed by ", $pc->peerhost,":",$pc->peerport,"\n"; $sel->remove($pc); $sel->remove($rc); close $pc; close $rc; next; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: capturing syswrite failures
by kyle (Abbot) on Mar 01, 2007 at 18:28 UTC

    In case $data is empty,

    unless ( syswrite( $pc, $data ) == length $data ) { # ... }

    Or maybe just

    unless ( defined syswrite( $pc, $data ) ) { # ... }

    (Should it be considered an error if syswrite writes some number of bytes different from the length of the string you give it?)

      Should it be considered an error if syswrite writes some number of bytes different from the length of the string you give it?

      No.

      my $to_write = length($data); my $offset = 0; while ($to_write > 0) { my $written = syswrite($fh, $data, $to_write, $offset); die("Unable to write to ...: $!\n") if not defined $written; $to_write -= $written; $offset += $written; }