Commit 85aac3c8 authored by Leigh B Stoller's avatar Leigh B Stoller

Minor rework to handle multiple events (coming in faster) more

efficiently.
parent f8fe96a9
#!/usr/bin/perl #!/usr/bin/perl
# #
# Copyright (c) 2002-2004 University of Utah and the Flux Group. # Copyright (c) 2002-2016 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -74,6 +74,26 @@ if ($expt) { ...@@ -74,6 +74,26 @@ if ($expt) {
%$tuple = ( expt => $expt ); %$tuple = ( expt => $expt );
} }
my $gotone;
sub callbackFunc($$$) {
my ($handle,$notification,$data) = @_;
my $time = time();
my $site = event_notification_get_site($handle, $notification);
my $expt = event_notification_get_expt($handle, $notification);
my $group = event_notification_get_group($handle, $notification);
my $host = event_notification_get_host($handle, $notification);
my $objtype = event_notification_get_objtype($handle, $notification);
my $objname = event_notification_get_objname($handle, $notification);
my $eventtype = event_notification_get_eventtype($handle,
$notification);
print "Event: $time $site $expt $group $host $objtype $objname " .
"$eventtype\n";
$gotone++;
}
if (!event_subscribe($handle,\&callbackFunc,$tuple)) { if (!event_subscribe($handle,\&callbackFunc,$tuple)) {
die "Could not subscribe to event\n"; die "Could not subscribe to event\n";
} }
...@@ -84,8 +104,12 @@ if (!event_subscribe($handle,\&callbackFunc,$tuple)) { ...@@ -84,8 +104,12 @@ if (!event_subscribe($handle,\&callbackFunc,$tuple)) {
# a wacky way to get usleep() ) # a wacky way to get usleep() )
# #
while (1) { while (1) {
$gotone = 1;
while ($gotone) {
$gotone = 0;
event_poll($handle); event_poll($handle);
select(undef, undef, undef, 0.25); }
event_poll_blocking($handle, 5000);
} }
if (event_unregister($handle) == 0) { if (event_unregister($handle) == 0) {
...@@ -94,18 +118,3 @@ if (event_unregister($handle) == 0) { ...@@ -94,18 +118,3 @@ if (event_unregister($handle) == 0) {
exit(0); exit(0);
sub callbackFunc($$$) {
my ($handle,$notification,$data) = @_;
my $time = time();
my $site = event_notification_get_site($handle, $notification);
my $expt = event_notification_get_expt($handle, $notification);
my $group = event_notification_get_group($handle, $notification);
my $host = event_notification_get_host($handle, $notification);
my $objtype = event_notification_get_objtype($handle, $notification);
my $objname = event_notification_get_objname($handle, $notification);
my $eventtype = event_notification_get_eventtype($handle,
$notification);
print "Event: $time $site $expt $group $host $objtype $objname " .
"$eventtype\n";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment