SubProcess.pm: added read function for convenience
git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@8348 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -114,6 +114,16 @@ sub parent() {
|
||||
return $self->{parent};
|
||||
}
|
||||
|
||||
# this function is called from the parent to read from the child
|
||||
# returns undef on error or if nothing was read
|
||||
sub read() {
|
||||
|
||||
my $self= shift;
|
||||
my ($bytes, $result);
|
||||
$bytes= sysread($self->child(), $result, 1024*1024);
|
||||
return defined($bytes) ? $result : undef;
|
||||
}
|
||||
|
||||
# starts the child process
|
||||
sub run() {
|
||||
|
||||
|
||||
@@ -175,14 +175,10 @@ sub SubProcessTester_Read($) {
|
||||
|
||||
# here we read from the global select loop what was
|
||||
# written in the onRun function
|
||||
my ($bytes, $result);
|
||||
$bytes= sysread($subprocess->child(), $result, 1024*1024);
|
||||
if(defined($bytes)) {
|
||||
my $result= $subprocess->read();
|
||||
if(defined($result)) {
|
||||
chomp $result;
|
||||
readingsSingleUpdate($hash, "step", $result, 1);
|
||||
} else {
|
||||
Log3 $hash, 2, "$name: $!";
|
||||
$result= undef;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user