3 # Run the same way as "test-pod.pl". This is supposed to be an
4 # exactly equivalent program but written using the ZOOM-Perl
5 # asynchronous-event API directly rather than through the intermediary
14 printf STDERR "Usage: $0 <target1> [<target2> ...]\n";
18 ZOOM::Log::mask_str("appl");
20 my %rs; # maps connection to result-set
21 my %state; # maps connection to app. state structure
22 foreach my $target (@ARGV) {
23 my $conn = new ZOOM::Connection($target, 0, async => 1,
24 elementSetName => "b");
26 $rs{$conn} = $conn->search_pqf("the");
30 while ((my $i = ZOOM::event(\@conn)) != 0) {
31 my $conn = $conn[$i-1];
32 my $ev = $conn->last_event();
33 my $evstr = ZOOM::event_str($ev);
34 ZOOM::Log::log("pod", "connection ", $i-1, ": event $ev ($evstr)");
35 $conn->check(); # die if any errors occur
37 if ($ev == ZOOM::Event::RECV_SEARCH) {
38 $res = completed_search($conn, \%state, $rs{$conn}, $ev);
39 die "recieve search failed with error $res" if $res;
40 } elsif ($ev == ZOOM::Event::RECV_RECORD) {
41 $res = got_record($conn, \%state, $rs{$conn}, $ev);
42 die "recieve record failed with error $res" if $res;
49 sub completed_search {
50 my($conn, $arg, $rs, $event) = @_;
52 my $host = $conn->option("host");
53 print "$host : found ", $rs->size(), " records\n";
54 my %state = (next_to_show => 0, next_to_fetch => 0);
55 request_records($conn, $rs, \%state, 2);
56 $arg->{$host} = \%state;
61 my($conn, $arg, $rs, $event) = @_;
63 my $host = $conn->option("host");
64 my $state = $arg->{$host};
67 # Sanity-checking assertions. These should be impossible
68 my $ns = $state->{next_to_show};
69 my $nf = $state->{next_to_fetch};
71 die "next_to_show > next_to_fetch ($ns > $nf)";
72 } elsif ($ns == $nf) {
73 die "next_to_show == next_to_fetch ($ns)";
77 my $i = $state->{next_to_show}++;
78 my $rec = $rs->record($i);
79 print "$host: record $i is ", render_record($rec), "\n";
80 request_records($conn, $rs, $state, 3)
81 if $i == $state->{next_to_fetch}-1;
87 my($conn, $rs, $state, $count) = @_;
89 my $i = $state->{next_to_fetch};
90 ZOOM::Log::log("appl", "requesting $count records from $i for ",
91 $conn->option("host"));
92 $rs->records($i, $count, 0);
93 $state->{next_to_fetch} += $count;
99 return "undefined" if !defined $rec;
100 return "'" . $rec->render() . "'";