mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
SubProcess.pm: buffer reads, messages amended
git-svn-id: https://svn.fhem.de/fhem/trunk@14334 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
149bbb8dd7
commit
f617a5408b
@ -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,
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user