Try checking to see what syswrite returns. Maybe your call is not writing all of buffer. If so syswrite will return how much it actually wrote. You could then used the offset parament of syswrite to continue to write the rest of the buffer. I have a similar app that writes data to a socket connection. Here is how I implement it...
#
# Sub used to write data to FDMS.
# Writing requires that the first 6 bytes are NBxxxx
# where xxxx is the total number of bytes to write plus the NBxxxx.
#
sub write {
my ($this, $buffer) = @_;
my $thisSub = (caller(0))[3];
my $socket = $this->{socket};
my $select = $this->{select};
my $verbose = $this->{verbose};
my $timeout = $this->{writeTimeout};
$buffer = sprintf('NB%04d%s', length($buffer) + 6, $buffer);
my $length = length($buffer);
my $offset;
my $bytes;
while ($length > 0) {
if ($select->can_write($timeout)) {
$bytes = $socket->syswrite($buffer, $length, $offset);
croak "Unable to write: $!" unless defined $bytes;
$offset += $bytes;
$length -= $bytes;
print "$thisSub($bytes) = $buffer\n" if $verbose;
}
else {
croak 'timeout on write';
}
}
}
UPDATE:
try putting in a signal handler for SIGPIPE to see if you can get around the problem.
Something like...
$SIG{PIPE} = sub { die "SIGPIPE\n"; };
...just to see if it is happening.
UPDATE:
See this post...
script dies with 'broken pipe'-message, even in eval
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.