From 2328e7794a43a0e446e59e4283ba4c667cc2bb0f Mon Sep 17 00:00:00 2001 From: minima Date: Sun, 1 Apr 2001 21:06:23 +0000 Subject: [PATCH] try to thread for MSWin32 --- Changes | 1 + perl/winclient.pl | 49 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Changes b/Changes index 63711b81..ca4487b6 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ 01Apr01======================================================================= 1. changed agwrestart semantics. You need to use main::agwrestart() in your crontabs rather than AGWMsg::init(); +2. try to thread winclient.pl for MSWin32. 31Mar01======================================================================= 1. added agwrestart command 2. add Iains Windoze installation manual (g0vgs) diff --git a/perl/winclient.pl b/perl/winclient.pl index 58db0b8c..f03af705 100755 --- a/perl/winclient.pl +++ b/perl/winclient.pl @@ -29,6 +29,7 @@ BEGIN { use IO::Socket; use DXVars; use IO::File; +use Config; # # deal with args @@ -64,22 +65,43 @@ unless ($handle) { exit(0); } -# Fork one in / one out ..... +STDOUT->autoflush(1); +$handle->autoflush(1); +print $handle "A$call|local\n"; + +# Fork or thread one in / one out ..... my $childpid; -die "can't fork: $!" unless defined($childpid = fork()); +my $t; +if ($Config{usethreads}) { + require Thread; +# print "Using Thread Method\n"; + $t = Thread->new(\&dostdin); + donetwork(); + $t->join; + kill(-1, $$); +} else { +# print "Using Fork Method\n"; + die "can't fork: $!" unless defined($childpid = fork()); + if ($childpid) { + donetwork(); + kill 'TERM', $childpid; + } else { + dostdin(); + } +} +exit 0; + -# the communication ..... -if ($childpid) { +sub donetwork +{ my ($lastend, $end) = ("\n", "\n"); - STDOUT->autoflush(1); while (defined (my $msg = <$handle>)) { my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/; next unless defined $sort; $line =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg; if ($sort eq 'Z') { - kill 'TERM', $childpid; - exit(0); + return; } elsif ($sort eq 'E' || $sort eq 'B') { ; } else { @@ -93,14 +115,17 @@ if ($childpid) { print $begin . $line . $end; } } - kill 'TERM', $childpid; -} else { - $handle->autoflush(1); - print $handle "A$call|local\n"; +} + +sub dostdin +{ while (defined (my $line = )) { print $handle "I$call|$line\n"; + if ($t && ($line =~ /^b/i || $line =~ /^q/i)) { + return; + } } } -exit 0; + -- 2.43.0