Changeset 17229 for gsdl/trunk/perllib
- Timestamp:
- 2008-09-09T19:05:10+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/downloaders/Z3950Download.pm
r17220 r17229 112 112 print STDERR "<<Defined Maximum>>\n"; 113 113 114 print STDERR "Opening connection to $url\n"; 115 116 my $yaz = $self->{'yaz'}; 117 118 my $childpid = open2(*YAZOUT, *YAZIN, $yaz) 119 or (print STDERR "<<Finished>>\n" and die "can't open pipe to yaz-client: $!"); 120 $self->{'YAZOUT'} = *YAZOUT; 121 $self->{'YAZIN'} = *YAZIN; 122 123 $strOpen = $self->open_connection("open $url"); 124 125 if (!$strOpen) { 126 print STDERR "Cannot connect to $url\n"; 127 print STDERR "<<Finished>>\n"; 128 return 0; 129 } 114 $strOpen = $self->start_yaz($url); 130 115 131 116 print STDERR "Access database: \"$self->{'database'}\"\n"; … … 148 133 $self->saveRecords($strRecords,$hashGeneralOptions->{'cache_dir'},$intMaxRecords); 149 134 print STDERR "Closing connection...\n"; 135 136 $self->quit_yaz(); 137 return 1; 138 } 139 140 141 sub start_yaz 142 { 143 my ($self, $url) = @_; 144 145 print STDERR "Opening connection to $url\n"; 146 147 my $yaz = $self->{'yaz'}; 148 149 my $childpid = open2(*YAZOUT, *YAZIN, $yaz) 150 or (print STDERR "<<Finished>>\n" and die "can't open pipe to yaz-client: $!"); 151 $self->{'YAZOUT'} = *YAZOUT; 152 $self->{'YAZIN'} = *YAZIN; 153 154 my $strOpen = $self->open_connection("open $url"); 155 156 if (!$strOpen) { 157 print STDERR "Cannot connect to $url\n"; 158 print STDERR "<<Finished>>\n"; 159 return 0; 160 } 161 return $strOpen; 162 } 163 164 sub quit_yaz 165 { 166 my ($self) = shift (@_); 167 150 168 print STDERR "<<Finished>>\n"; 151 169 152 170 # need to send the quit command, else yaz-client is still running in the background 153 171 $self->run_command_without_output("quit"); 154 close(YAZOUT); 155 close(YAZIN); 156 return 1; 172 close($self->{'YAZIN'}); # close the input to yaz. It also flushes quit command to yaz. 173 174 # make sure nothing is being output by yaz 175 my $output = $self->{'YAZOUT'}; 176 my $line; 177 while (defined ($line = <$output>)) { 178 print STDERR "***### $line"; 179 } 180 181 close($self->{'YAZOUT'}); 157 182 } 158 183 … … 164 189 my $out = $self->{'YAZOUT'}; 165 190 166 $_= <$out>;191 my $opening_line = <$out>; 167 192 168 return ( /Connecting...OK/i)? 1: 0;193 return ($opening_line =~ m/Connecting...OK/i)? 1: 0; 169 194 170 195 } … … 269 294 my $readRecord = 0; 270 295 271 while (my $strLine = <YAZOUT>) 296 my $output = $self->{'YAZOUT'}; 297 while (my $strLine = <$output>) 272 298 { 273 299 … … 344 370 $url = $self->{'url'} unless defined $url; 345 371 346 my $yaz = $self->{'yaz'}; 347 348 my $childpid = open2(*YAZOUT, *YAZIN, $yaz) 349 or die "can't open pipe to yaz-client: $!"; 350 351 $self->{'YAZOUT'} = *YAZOUT; 352 $self->{'YAZIN'} = *YAZIN; 353 354 my $strOpen = $self->open_connection("open $url"); 355 356 if (!$strOpen) { 357 print STDERR "Cannot connect to $url\n"; 358 print STDERR "<<Finished>>\n"; 359 return 0; 360 } 361 362 372 my $strOpen = $self->start_yaz(); 373 363 374 $strOpen = $self->run_command_with_output("open $url","^Options"); 364 365 375 366 376 $strOpen =~ s/Z> //g; … … 369 379 print STDERR $strOpen; 370 380 371 print STDERR "<<Finished>>\n"; 372 373 # need to send the quit command, else yaz-client is still running in the background 374 $self->run_command_without_output("quit"); 375 close(YAZOUT); 376 close(YAZIN); 381 $self->quit_yaz(); 377 382 378 383 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.