diff --git a/fhem/CHANGED b/fhem/CHANGED index 2f956e525..68e4d9c93 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: SubProcess.pm: buffer reads, messages amended - feature: 98_alarmclock: New feature PresenceDevice - change: 49_SSCam: version 2.2.1, last record playback possible as iFrame, deviceoverview available, diff --git a/fhem/FHEM/SubProcess.pm b/fhem/FHEM/SubProcess.pm index 847cae137..2ace9471d 100644 --- a/fhem/FHEM/SubProcess.pm +++ b/fhem/FHEM/SubProcess.pm @@ -125,7 +125,7 @@ sub wait() { if(defined($pid)) { main::Log3 $pid, 5, "Waiting for SubProcess $pid..."; waitpid($pid, 0); - main::Log3 $pid, 5, "SubProcess $pid terminated..."; + main::Log3 $pid, 5, "SubProcess $pid terminated."; } } @@ -176,8 +176,6 @@ sub parent() { # this is a helper function for reading # returns 1 datagram or undef on error -# this version does not handle split transmissions that result in short datagrams -# Todo: buffer such datagrams sub readFrom() { my ($self, $fh) = @_; @@ -209,15 +207,16 @@ sub readFrom() { } # Read datagram - my $size = unpack ('N', $header); - my $bytes = sysread ($fh, $data, $size); - if (!defined ($bytes)) { - $self->{lasterror} = $!; - return undef; - } - elsif ($bytes != $size) { - $self->{lasterror} = "read: incomplete data"; - return undef; + my $size = unpack ('N', $header); + my $buffer; + while($size> 0) { + my $bytes = sysread ($fh, $buffer, $size); + if (!defined ($bytes)) { + $self->{lasterror} = $!; + return undef; + } + $data.= $buffer; + $size-= $bytes; } return $data; @@ -312,6 +311,7 @@ sub run() { # CHILD # run + main::Log3 undef, 5, "SubProcess $$ started."; my $onRun= $self->{onRun}; if(defined($onRun)) { eval { &$onRun($self) }; @@ -325,7 +325,7 @@ sub run() { main::Log3 undef, 2, "SubProcess: onExit returned error: $@" if($@); } - #close(PARENT); + main::Log3 undef, 5, "SubProcess $$ ended."; POSIX::_exit(0); } else {