line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Date: 2003/05/05 16:50:12 $ |
2
|
|
|
|
|
|
|
# $Revision: 1.4 $ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Net::Z3950::AsyncZ::ZLoop; |
6
|
1
|
|
|
1
|
|
1118
|
use Net::Z3950::AsyncZ::Errors; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
7
|
1
|
|
|
1
|
|
5
|
use Event qw(loop unloop); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
184
|
use Net::Z3950::AsyncZ::Report; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Net::Z3950::AsyncZ::ZSend; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $_ERROR_VAL = Net::Z3950::AsyncZ::Errors::errorval(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#$SIG{ALRM} = sub { exit $_ERROR_VAL + 3; }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use strict; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my($_host,$_port,$_db,$_query); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# $self->{options} is a _params object |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
|
|
|
|
|
|
my ($class, $host,$port,$db,$query, $options)=@_; |
25
|
|
|
|
|
|
|
($_host,$_port,$_db,$_query) = ($host,$port,$db,$query); |
26
|
|
|
|
|
|
|
my $self = { |
27
|
|
|
|
|
|
|
conn => 0, Zsend => 0, inLoop => 0, options=>$options, |
28
|
|
|
|
|
|
|
pipetimeout=>undef, interval=>undef, rsize=>0 |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $tm = $self->{options}->_getFieldValue('pipetimeout'); |
32
|
|
|
|
|
|
|
$self->{pipetimeout} = $tm ? $tm : 20; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $interval = $self->{options}->_getFieldValue('interval'); |
35
|
|
|
|
|
|
|
$self->{interval} = $interval ? $interval : 5; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
bless $self, $class; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub setTimer { |
41
|
|
|
|
|
|
|
my ($self, $interval)= @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->{start} = time(); |
44
|
|
|
|
|
|
|
$self->{watcher} = Event->timer(at=>1,interval =>$self->{interval}, cb=> sub { $self->timerCallBack(); } ); |
45
|
|
|
|
|
|
|
loop(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub timerCallBack { |
49
|
|
|
|
|
|
|
my $self=shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return if ($self->{Zsend}) && $self->{Zsend}->connection(); |
52
|
|
|
|
|
|
|
my $Seconds = time(); |
53
|
|
|
|
|
|
|
my $endval = $Seconds - $self->{start}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($endval >= $self->{pipetimeout}) { |
56
|
|
|
|
|
|
|
exit $_ERROR_VAL + 2; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return if($self->{inLoop}); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->{inLoop}=1; |
62
|
|
|
|
|
|
|
$self->{Zsend} = |
63
|
|
|
|
|
|
|
Net::Z3950::AsyncZ::ZSend->new( |
64
|
|
|
|
|
|
|
query=>$_query,host=>$_host,db=>$_db, |
65
|
|
|
|
|
|
|
port=>$_port,options=>$self->{options} |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
## alarms are set for some conditions in which the event loop is swallowed |
70
|
|
|
|
|
|
|
## up by Net::Z3950 and either doesn't or takes too long to return |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# alarm($self->{pipetimeout}/2); ; |
73
|
|
|
|
|
|
|
$self->{conn} = $self->{Zsend}->connection(); |
74
|
|
|
|
|
|
|
# alarm(0); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# alarm($self->{pipetimeout}); |
77
|
|
|
|
|
|
|
if($self->{conn}) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
$self->{Zsend}->sendQuery(); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if(!$self->{Zsend}->rs() || !$self->{Zsend}->rsize()) { |
82
|
|
|
|
|
|
|
Net::Z3950::AsyncZ::Errors::reportNoEntries(); |
83
|
|
|
|
|
|
|
$self->{Zsend}->closedown(); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
$self->{rsize} = $self->{Zsend}->rsize() if $self->{Zsend}->rs(); |
86
|
|
|
|
|
|
|
my $report = Net::Z3950::AsyncZ::Report->new($self->{Zsend}->rs(), $self->{options}); |
87
|
|
|
|
|
|
|
$report->reportResult(); |
88
|
|
|
|
|
|
|
$self->{report} = $report->{result}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$self->{Zsend}->closedown(); |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
exit $_ERROR_VAL + 1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
# alarm(0); |
95
|
|
|
|
|
|
|
$self->{watcher}->cancel(); |
96
|
|
|
|
|
|
|
unloop(); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |