When the time comes to wait for responses to arrive, block on the XMPP
socket (which uses select() under the covers) until data arrives,
instead of looping furiously and calling receive in non-blocking mode.
Before this change, waiting on responses resulted in long-running CPU
spikes.
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
sub session_wait {
my $self = shift;
my $all = shift;
+ my $xmpp = OpenSRF::Transport::PeerHandle->retrieve;
my $count;
if ($all) {
$count = $self->running;
while ($self->running) {
+ # block on the xmpp socket until data arrives
+ $xmpp->process(-1);
$self->session_reap;
}
return $count;
} else {
while(($count = $self->session_reap) == 0 && $self->running) {
- usleep 100;
+ # block on the xmpp socket until data arrives
+ $xmpp->process(-1);
}
return $count;
}