projects
/
spider.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
11fa76e
)
try to thread for MSWin32
author
minima
<minima>
Sun, 1 Apr 2001 21:06:23 +0000
(21:06 +0000)
committer
minima
<minima>
Sun, 1 Apr 2001 21:06:23 +0000
(21:06 +0000)
Changes
patch
|
blob
|
history
perl/winclient.pl
patch
|
blob
|
history
diff --git
a/Changes
b/Changes
index 63711b810c3dbc74f6b86b8eaaae0a9e099e5e3b..ca4487b6ff3b689acbc34ef15bb10bfa2a3d0802 100644
(file)
--- 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();
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)
31Mar01=======================================================================
1. added agwrestart command
2. add Iains Windoze installation manual (g0vgs)
diff --git
a/perl/winclient.pl
b/perl/winclient.pl
index 58db0b8c95f4ce960f4adbddabac9cd618738335..f03af7052655f393770e327d36822a2831347702 100755
(executable)
--- a/
perl/winclient.pl
+++ b/
perl/winclient.pl
@@
-29,6
+29,7
@@
BEGIN {
use IO::Socket;
use DXVars;
use IO::File;
use IO::Socket;
use DXVars;
use IO::File;
+use Config;
#
# deal with args
#
# deal with args
@@
-64,22
+65,43
@@
unless ($handle) {
exit(0);
}
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;
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");
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') {
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 {
} elsif ($sort eq 'E' || $sort eq 'B') {
;
} else {
@@
-93,14
+115,17
@@
if ($childpid) {
print $begin . $line . $end;
}
}
print $begin . $line . $end;
}
}
- kill 'TERM', $childpid;
-} else {
- $handle->autoflush(1);
- print $handle "A$call|local\n";
+}
+
+sub dostdin
+{
while (defined (my $line = <STDIN>)) {
print $handle "I$call|$line\n";
while (defined (my $line = <STDIN>)) {
print $handle "I$call|$line\n";
+ if ($t && ($line =~ /^b/i || $line =~ /^q/i)) {
+ return;
+ }
}
}
}
}
-exit 0;
+