1 # $Id: async.pl,v 1.2 2006-11-02 17:48:26 mike Exp $
3 # See ../README for a description of this program.
4 # perl -I../../blib/lib -I../../blib/arch async.pl <t1> [...] <tN> <query>
6 # perl -I../../blib/lib -I../../blib/arch async.pl z3950.loc.gov:7090/Voyager z3950.indexdata.com:210/gils endeavor.flo.org:7090/Voyager mineral
13 print STDERR "Usage: $0 target1 target2 ... targetN query\n";
14 print STDERR " eg. $0 z3950.indexdata.dk/gils localhost:9999 fish\n";
19 my(@z, @r); # connections, result sets
20 my $o = new ZOOM::Options();
21 $o->option(async => 1);
23 # Get first 10 records of result set (using piggyback)
24 $o->option(count => 10);
26 # Preferred record syntax
27 $o->option(preferredRecordSyntax => "usmarc");
28 $o->option(elementSetName => "F");
30 # Connect to all targets: options are the same for all of them
31 for (my $i = 0; $i < $n; $i++) {
32 $z[$i] = create ZOOM::Connection($o);
33 $z[$i]->connect($ARGV[$i]);
37 for (my $i = 0; $i < $n; $i++) {
38 $r[$i] = $z[$i]->search_pqf($ARGV[-1]);
41 # Network I/O. Pass number of connections and array of connections
45 while (($i = ZOOM::event(\@z)) != 0) {
46 my $ev = $z[$i-1]->last_event();
47 print("connection ", $i-1, ": event $ev (", ZOOM::event_str($ev), ")\n");
48 last if $ev == ZOOM::Event::ZEND;
52 # Not the end of the whole loop; one server is ready to display
54 my $tname = $ARGV[$i];
55 my($error, $errmsg, $addinfo, $diagset) = $z[$i]->error_x();
57 print STDERR "$tname error: $errmsg ($error) $addinfo\n";
61 # OK, no major errors. Look at the result count
62 my $size = $r[$i]->size();
63 print "$tname: $size hits\n";
65 # Go through all records at target
66 $size = 10 if $size > 10;
67 for (my $pos = 0; $pos < $size; $pos++) {
68 print "$tname: fetching ", $pos+1, " of $size\n";
69 my $tmp = $r[$i]->record($pos);
71 print "$tname: can't get record ", $pos+1, "\n";
74 my $rec = $tmp->render();
76 print "$tname: can't render record ", $pos+1, "\n";
79 print $pos+1, "\n", $rec, "\n";
84 if (--$nremaining > 0) {
89 for (my $i = 0; $i < $n; $i++) {