1 # $Id: zoomtst3.pl,v 1.2 2006-04-07 07:18:27 mike Exp $
3 # See ../README for a description of this program.
4 # perl -I../../blib/lib -I../../blib/arch zoomtst3.pl <t1> [...] <tN> <query>
11 print STDERR "Usage: $0 target1 target2 ... targetN query\n";
12 print STDERR " eg. $0 bagel.indexdata.dk/gils localhost:9999 fish\n";
17 my(@z, @r); # connections, result sets
18 my $o = Net::Z3950::ZOOM::options_create();
19 Net::Z3950::ZOOM::options_set($o, async => 1);
21 # Get first 10 records of result set (using piggyback)
22 Net::Z3950::ZOOM::options_set($o, count => 10);
24 # Preferred record syntax
25 Net::Z3950::ZOOM::options_set($o, preferredRecordSyntax => "usmarc");
26 Net::Z3950::ZOOM::options_set($o, elementSetName => "F");
28 # Connect to all targets: options are the same for all of them
29 for (my $i = 0; $i < $n; $i++) {
30 $z[$i] = Net::Z3950::ZOOM::connection_create($o);
31 Net::Z3950::ZOOM::connection_connect($z[$i], $ARGV[$i], 0);
35 for (my $i = 0; $i < $n; $i++) {
36 $r[$i] = Net::Z3950::ZOOM::connection_search_pqf($z[$i], $ARGV[-1]);
39 # Network I/O. Pass number of connections and array of connections
40 while ((my $i = Net::Z3950::ZOOM::event([ @z ])) != 0) {
41 my $ev = Net::Z3950::ZOOM::connection_last_event($z[$i-1]);
42 print("connection ", $i-1, ": event $ev (",
43 Net::Z3950::ZOOM::eventstr($ev), ")\n");
46 # No more to be done. Inspect results
47 for (my $i = 0; $i < $n; $i++) {
48 my($error, $errmsg, $addinfo) = (undef, "dummy", "dummy");
49 my $tname = $ARGV[$i];
51 # Display errors if any
52 $error = Net::Z3950::ZOOM::connection_error($z[$i], $errmsg, $addinfo);
54 print STDERR "$tname error: $errmsg ($error) $addinfo\n";
58 # OK, no major errors. Look at the result count
59 my $size = Net::Z3950::ZOOM::resultset_size($r[$i]);
60 print "$tname: $size hits\n";
62 # Go through all records at target
63 $size = 10 if $size > 10;
64 for (my $pos = 0; $pos < $size; $pos++) {
65 my $len = 0; # length of buffer rec
66 print "$tname: fetching ", $pos+1, " of $size\n";
67 my $tmp = Net::Z3950::ZOOM::resultset_record($r[$i], $pos);
69 print "$tname: can't get record ", $pos+1, "\n";
72 my $rec = Net::Z3950::ZOOM::record_get($tmp, "render", $len);
73 # if rec is non-null, we got a record for display
75 print $pos+1, "\n", $rec, "\n";
81 for (my $i = 0; $i < $n; $i++) {
82 Net::Z3950::ZOOM::resultset_destroy($r[$i]);
83 Net::Z3950::ZOOM::connection_destroy($z[$i]);
86 Net::Z3950::ZOOM::options_destroy($o);