Fall out of wait() when there are no active connections left.
[irspy-moved-to-github.git] / lib / ZOOM / Pod.pm
index 23c714d..5c554ec 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Pod.pm,v 1.13 2006-06-21 14:31:24 mike Exp $
+# $Id: Pod.pm,v 1.18 2006-07-25 16:51:22 mike Exp $
 
 package ZOOM::Pod;
 
@@ -228,8 +228,8 @@ have one search active on it at a time: this allows the pod to
 maintain the one-to-one mapping between connections and result-sets.
 Submitting a new search on a connection before the old one has
 completed will result in a total failure in the nature of causality,
-and the spontaneous existence-failure of the universe.  Do not do
-this.
+and the spontaneous existence-failure of the universe.  Try to avoid
+doing this too often.
 
 =cut
 
@@ -238,7 +238,9 @@ sub search_pqf {
     my($pqf) = @_;
 
     foreach my $i (0..@{ $this->{conn} }-1) {
-       $this->{rs}->[$i] = $this->{conn}->[$i]->search_pqf($pqf);
+       my $conn = $this->{conn}->[$i];
+       $this->{rs}->[$i] = $conn->search_pqf($pqf)
+           if !$conn->option("pod_omit");
     }
 }
 
@@ -265,6 +267,10 @@ indicates whether C<wait()> should continue (return-value 0) or return
 immediately (any other value).  Exception-handling callbacks may of
 course re-throw the exception.
 
+Connections that have the C<pod_omit> option set are omitted from
+consideration.  This is useful if, for example, a connection that is
+part of a pod is known to have encountered an unrecoverable error.
+
 =cut
 
 sub wait {
@@ -272,8 +278,30 @@ sub wait {
     my($arg) = @_;
 
     my $res = 0;
-    while ((my $i = ZOOM::event($this->{conn})) != 0) {
+
+    while (1) {
+       my @conn;
+       my @idxmap; # maps indexes into conn to global indexes
+       foreach my $i (0 .. @{ $this->{conn} }-1) {
+           my $conn = $this->{conn}->[$i];
+           if ($conn->option("pod_omit")) {
+               #ZOOM::Log::log("pod", "connection $i omitted (",
+                              #$conn->option("host"), ")");
+             } else {
+                 push @conn, $conn;
+                 push @idxmap, $i;
+                 #ZOOM::Log::log("pod", "connection $i included (",
+                                #$conn->option("host"), ")");
+             }
+       }
+
+       last if @conn == 0;
+       my $i0 = ZOOM::event(\@conn);
+       last if $i0 == 0;
+       my $i = 1+$idxmap[$i0-1];
        my $conn = $this->{conn}->[$i-1];
+       die "connection-mapping screwup" if $conn ne $conn[$i0-1];
+
        my $ev = $conn->last_event();
        my $evstr = ZOOM::event_str($ev);
        ZOOM::Log::log("pod", "connection ", $i-1, ": event $ev ($evstr)");