# # 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'; } } } #### $SIG{PIPE} = sub { die "SIGPIPE\n"; };