… | |
… | |
159 | our @QUEUE; |
159 | our @QUEUE; |
160 | our $MAX_OUTSTANDING = 50; |
160 | our $MAX_OUTSTANDING = 50; |
161 | our $MIN_RECVQUEUE = 8; |
161 | our $MIN_RECVQUEUE = 8; |
162 | our $MAX_RECVQUEUE = 64; |
162 | our $MAX_RECVQUEUE = 64; |
163 | |
163 | |
164 | sub kick_job; # also --$BUSY |
164 | sub kick_job; |
165 | |
165 | |
166 | sub _send_pdu { |
166 | sub _send_pdu { |
167 | my ($pdu, $retries) = @_; |
167 | my ($pdu, $retries) = @_; |
168 | |
168 | |
169 | # mostly copied from Net::SNMP::Dispatch |
169 | # mostly copied from Net::SNMP::Dispatch |
… | |
… | |
171 | # Pass the PDU to Message Processing so that it can |
171 | # Pass the PDU to Message Processing so that it can |
172 | # create the new outgoing message. |
172 | # create the new outgoing message. |
173 | my $msg = $MESSAGE_PROCESSING->prepare_outgoing_msg ($pdu); |
173 | my $msg = $MESSAGE_PROCESSING->prepare_outgoing_msg ($pdu); |
174 | |
174 | |
175 | if (!defined $msg) { |
175 | if (!defined $msg) { |
|
|
176 | --$BUSY; |
176 | kick_job; |
177 | kick_job; |
177 | # Inform the command generator about the Message Processing error. |
178 | # Inform the command generator about the Message Processing error. |
178 | $pdu->status_information ($MESSAGE_PROCESSING->error); |
179 | $pdu->status_information ($MESSAGE_PROCESSING->error); |
179 | return; |
180 | return; |
180 | } |
181 | } |
… | |
… | |
189 | my $retry_w; $retry_w = AE::timer $pdu->timeout, 0, sub { |
190 | my $retry_w; $retry_w = AE::timer $pdu->timeout, 0, sub { |
190 | undef $retry_w; |
191 | undef $retry_w; |
191 | _send_pdu ($pdu, $retries); |
192 | _send_pdu ($pdu, $retries); |
192 | }; |
193 | }; |
193 | } else { |
194 | } else { |
|
|
195 | --$BUSY; |
194 | kick_job; |
196 | kick_job; |
195 | } |
197 | } |
196 | |
198 | |
197 | # Inform the command generator about the send() error. |
199 | # Inform the command generator about the send() error. |
198 | $pdu->status_information ($msg->error); |
200 | $pdu->status_information ($msg->error); |
… | |
… | |
255 | # Cancel the timeout. |
257 | # Cancel the timeout. |
256 | my $rtimeout_w = $msg->timeout_id; |
258 | my $rtimeout_w = $msg->timeout_id; |
257 | if ($$rtimeout_w) { |
259 | if ($$rtimeout_w) { |
258 | undef $$rtimeout_w; |
260 | undef $$rtimeout_w; |
259 | |
261 | |
|
|
262 | --$BUSY; |
260 | kick_job; |
263 | kick_job; |
261 | |
264 | |
262 | unless (--$TRANSPORT[$fileno][0]) { |
265 | unless (--$TRANSPORT[$fileno][0]) { |
263 | delete $TRANSPORT[$fileno]; |
266 | delete $TRANSPORT[$fileno]; |
264 | return; |
267 | return; |
… | |
… | |
286 | _send_pdu ($pdu, $retries); |
289 | _send_pdu ($pdu, $retries); |
287 | } else { |
290 | } else { |
288 | $MESSAGE_PROCESSING->msg_handle_delete ($pdu->msg_id); |
291 | $MESSAGE_PROCESSING->msg_handle_delete ($pdu->msg_id); |
289 | $pdu->status_information ("No response from remote host '%s'", $pdu->hostname); |
292 | $pdu->status_information ("No response from remote host '%s'", $pdu->hostname); |
290 | |
293 | |
|
|
294 | --$BUSY; |
291 | kick_job; |
295 | kick_job; |
292 | } |
296 | } |
293 | }) |
297 | }) |
294 | ); |
298 | ); |
295 | } else { |
299 | } else { |
|
|
300 | --$BUSY; |
296 | kick_job; |
301 | kick_job; |
297 | } |
302 | } |
298 | } |
303 | } |
299 | |
304 | |
300 | sub kick_job { |
305 | sub kick_job { |
301 | --$BUSY; |
|
|
302 | |
|
|
303 | while ($BUSY < $MAX_OUTSTANDING) { |
306 | while ($BUSY < $MAX_OUTSTANDING) { |
304 | my $pdu = shift @QUEUE |
307 | my $pdu = shift @QUEUE |
305 | or last; |
308 | or last; |
306 | |
309 | |
307 | ++$BUSY; |
310 | ++$BUSY; |
308 | |
|
|
309 | _send_pdu $pdu, $pdu->retries; |
311 | _send_pdu $pdu, $pdu->retries; |
310 | } |
312 | } |
311 | |
313 | |
312 | $DONE and $DONE->() unless $BUSY; |
314 | $DONE and $DONE->() unless $BUSY; |
313 | } |
315 | } |
… | |
… | |
320 | if ($delay > 0) { |
322 | if ($delay > 0) { |
321 | ++$BUSY; |
323 | ++$BUSY; |
322 | my $delay_w; $delay_w = AE::timer $delay, 0, sub { |
324 | my $delay_w; $delay_w = AE::timer $delay, 0, sub { |
323 | undef $delay_w; |
325 | undef $delay_w; |
324 | push @QUEUE, $pdu; |
326 | push @QUEUE, $pdu; |
|
|
327 | --$BUSY; |
325 | kick_job; |
328 | kick_job; |
326 | }; |
329 | }; |
327 | return 1; |
330 | return 1; |
328 | } |
331 | } |
329 | |
332 | |
… | |
… | |
340 | undef $DONE; |
343 | undef $DONE; |
341 | } |
344 | } |
342 | } |
345 | } |
343 | |
346 | |
344 | sub one_event($) { |
347 | sub one_event($) { |
|
|
348 | # should not ever be used |
345 | AnyEvent->one_event; #d# todo |
349 | AnyEvent->one_event; #d# todo |
346 | } |
350 | } |
347 | |
351 | |
348 | sub set_max_outstanding($) { |
352 | sub set_max_outstanding($) { |
349 | $MAX_OUTSTANDING = $_[0]; |
353 | $MAX_OUTSTANDING = $_[0]; |
350 | |
|
|
351 | ++$BUSY; # kick_job decrements $BUSY |
|
|
352 | kick_job; |
354 | kick_job; |
353 | } |
355 | } |
354 | |
356 | |
355 | =head1 SEE ALSO |
357 | =head1 SEE ALSO |
356 | |
358 | |