Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

input loop, reading in child process

  • Loading branch information...
commit 8cbeb66a2279e55d1e11727c9caea5158ccd1edf 1 parent 3bca8ea
Brad Fitzpatrick authored
Showing with 24 additions and 5 deletions.
  1. +24 −5 denon.pl
29 denon.pl
View
@@ -34,12 +34,31 @@
"ff f0", # suboption end
));
-expect_from_denon("BridgeCo AG Telnet server\x0a\x0d");
+# expect_from_denon("BridgeCo AG Telnet server\x0a\x0d");
-print "Reading...\n";
-my $buf;
-while (sysread($sock, $buf, 300)) {
- print "Read: [", printable($buf), "]\n";
+my $child = fork;
+unless (defined($child)) {
+ die "Fork failure.";
+}
+
+if ($child) {
+ # we're the parent process. accept input.
+ $| = 1;
+ while (1) {
+ print "DENON> ";
+ my $line = <STDIN>;
+ chomp $line;
+ if (!$line) {
+ next;
+ }
+ send_to_denon($line . "\x0d");
+ }
+} else {
+ # child process.
+ my $buf;
+ while (sysread($sock, $buf, 300)) {
+ print "Read: [", printable($buf), "]\n";
+ }
}
sub expect_from_denon {
Please sign in to comment.
Something went wrong with that request. Please try again.