From e643f0affd431d1b02e3d3294a54672a239a277f Mon Sep 17 00:00:00 2001 From: hjp Date: Wed, 8 Jan 2003 15:41:42 +0000 Subject: [PATCH] Copy messages from printer to stderr. --- jetdirectprint/jetdirectprint | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/jetdirectprint/jetdirectprint b/jetdirectprint/jetdirectprint index 4eaec34..861ce42 100755 --- a/jetdirectprint/jetdirectprint +++ b/jetdirectprint/jetdirectprint @@ -56,10 +56,27 @@ do { $socket || die "Unable to open socket after $retry_count retries."; -while () { - print $socket $_; -} +for (;;) { + my ($rin, $win, $ein); + my ($rout, $wout, $eout); + $rin = $win = $ein = ''; + vec($rin,fileno(STDIN),1) = 1; + vec($rin,fileno($socket),1) = 1; + $ein = $rin | $win; + my ($nfound,$timeleft) = + select($rout=$rin, $wout=$win, $eout=$ein, $timeout); + if (vec($rout,fileno(STDIN),1)) { + sysread(STDIN, $buf, 1024) or last; + print $socket $buf + or die "${config{'printer_ip'}}:${config{'port'}}: $!"; + } + if (vec($rout,fileno($socket),1)) { + sysread($socket, $buf, 1024) or last; + print STDERR "$0: ${config{'printer_ip'}}:${config{'port'}}: $buf\n"; + } +} + close($socket);