X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=lib%2FZOOM.pm;h=a571872096bcf440132148ad3cb8cffd5676d3f3;hb=3150ab3b918c91a56ca741dee054e1f44281c979;hp=a88be643ba026044927c98987ac6f7821d560a9a;hpb=9140a0be284807f6509e1b3800c6093633940e17;p=ZOOM-Perl-moved-to-github.git diff --git a/lib/ZOOM.pm b/lib/ZOOM.pm index a88be64..a571872 100644 --- a/lib/ZOOM.pm +++ b/lib/ZOOM.pm @@ -1,4 +1,4 @@ -# $Id: ZOOM.pm,v 1.42 2006-11-28 16:47:19 mike Exp $ +# $Id: ZOOM.pm,v 1.46 2007-02-26 14:36:55 mike Exp $ use strict; use warnings; @@ -34,7 +34,7 @@ sub MEMORY { Net::Z3950::ZOOM::ERROR_MEMORY } sub ENCODE { Net::Z3950::ZOOM::ERROR_ENCODE } sub DECODE { Net::Z3950::ZOOM::ERROR_DECODE } sub CONNECTION_LOST { Net::Z3950::ZOOM::ERROR_CONNECTION_LOST } -sub INIT { Net::Z3950::ZOOM::ERROR_INIT } +sub ZINIT { Net::Z3950::ZOOM::ERROR_INIT } sub INTERNAL { Net::Z3950::ZOOM::ERROR_INTERNAL } sub TIMEOUT { Net::Z3950::ZOOM::ERROR_TIMEOUT } sub UNSUPPORTED_PROTOCOL { Net::Z3950::ZOOM::ERROR_UNSUPPORTED_PROTOCOL } @@ -337,12 +337,32 @@ sub _conn { sub _check { my $this = shift(); + my($always_die_on_error) = @_; my($errcode, $errmsg, $addinfo, $diagset) = (undef, "x", "x", "x"); $errcode = Net::Z3950::ZOOM::connection_error_x($this->_conn(), $errmsg, $addinfo, $diagset); - die new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset) - if $errcode; + if ($errcode) { + my $exception = new ZOOM::Exception($errcode, $errmsg, $addinfo, + $diagset); + if (!$this->option("async") || $always_die_on_error) { + ZOOM::Log::log("zoom_check", "throwing error $exception"); + die $exception; + } else { + ZOOM::Log::log("zoom_check", "not reporting error $exception"); + } + } +} + +# This wrapper for _check() is called only from outside the ZOOM +# module, and therefore only in situations where an asynchronous +# application is actively asking for an exception to be thrown if an +# error has been detected. So it passed always_die_on_error=1 to the +# underlying _check() method. +# +sub check { + my $this = shift(); + return $this->_check(1); } sub create { @@ -499,6 +519,12 @@ sub is_idle { return Net::Z3950::ZOOM::connection_is_idle($this->_conn()); } +sub peek_event { + my $this = shift(); + + return Net::Z3950::ZOOM::connection_peek_event($this->_conn()); +} + sub destroy { my $this = shift(); @@ -831,6 +857,7 @@ sub exception { my $this = shift(); my($errcode, $errmsg, $addinfo, $diagset) = $this->error(); + return undef if $errcode == 0; return new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset); }