Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed perl event loop

fixed event::queue initialization
event.pm and perl loops are tested
  • Loading branch information...
commit 4932dd97955faf49e7777420bb2fb196db7cb92a 1 parent 4536f65
Uri Guttman authored
View
18 lib/Stem/Event.pm
@@ -71,7 +71,7 @@ sub init_loop {
$loop_class->_init_loop() ;
-Stem::Event::Queue::_init_queue() if defined &Stem::Event::Queue::_init_queue ;
+#Stem::Event::Queue::_init_queue() if defined &Stem::Event::Queue::_init_queue ;
}
@@ -316,9 +316,7 @@ sub _get_loop_class {
package Stem::Event::Plain ;
-BEGIN {
- @Stem::Event::Plain::ISA = qw( Stem::Event ) ;
-}
+our @ISA = qw( Stem::Event ) ;
=head2 Stem::Event::Plain::new
@@ -365,7 +363,7 @@ sub new {
my $self = Stem::Class::parse_args( $attr_spec_plain, @_ ) ;
return $self unless ref $self ;
- my $err = $self->_core_event_build( 'plain' ) ;
+ my $err = $self->_build_core_event( 'plain' ) ;
return $err if $err ;
return $self ;
@@ -375,7 +373,7 @@ sub new {
package Stem::Event::Signal ;
-BEGIN { our @ISA = qw( Stem::Event ) } ;
+our @ISA = qw( Stem::Event ) ;
=head2 Stem::Event::Signal::new
@@ -462,7 +460,7 @@ sub new {
package Stem::Event::Timer ;
-BEGIN { our @ISA = qw( Stem::Event ) } ;
+our @ISA = qw( Stem::Event ) ;
=head2 Stem::Event::Timer::new
@@ -652,7 +650,7 @@ sub timer_triggered {
package Stem::Event::IO ;
-BEGIN { our @ISA = qw( Stem::Event ) } ;
+our @ISA = qw( Stem::Event ) ;
sub init_io_timeout {
@@ -726,7 +724,7 @@ sub timed_out {
package Stem::Event::Read ;
-BEGIN { our @ISA = qw( Stem::Event::IO ) }
+our @ISA = qw( Stem::Event::IO ) ;
=head2 Stem::Event::Read::new
@@ -825,7 +823,7 @@ sub new {
package Stem::Event::Write ;
-BEGIN { our @ISA = qw( Stem::Event::IO ) } ;
+our @ISA = qw( Stem::Event::IO ) ;
=head2 Stem::Event::Write::new
View
20 lib/Stem/Event/Queue.pm
@@ -48,14 +48,13 @@ use warnings ;
use Socket;
use IO::Handle ;
-use base 'Exporter' ;
-our @EXPORT = qw( &mark_not_empty ) ;
+my( $self, $queue_read, $queue_write, $queue_read_event, $queue_has_event ) ;
-my( $queue_read, $queue_write, $queue_read_event ) ;
+sub _init_event_queue {
-my $self ;
+ return if $self ;
-sub _init_queue {
+ $self = bless {} ;
socketpair( $queue_read, $queue_write,
AF_UNIX, SOCK_STREAM, PF_UNSPEC ) || die <<DIE ;
@@ -64,7 +63,6 @@ DIE
#print fileno( $queue_read ), " FILENO\n" ;
- $self = bless {} ;
$queue_read->blocking( 0 ) ;
$queue_read_event = Stem::Event::Read->new(
@@ -78,27 +76,25 @@ DIE
}
-my $queue_is_marked ;
-
-sub mark_not_empty {
+sub queue_has_event {
my( $always_mark ) = @_ ;
# don't mark the queue if it is already marked and we aren't forced
# the signal queue always marks the queue
- return if $queue_is_marked && !$always_mark ;
+ return if $queue_has_event && !$always_mark ;
syswrite( $queue_write, 'x' ) ;
- $queue_is_marked = 1 ;
+ $queue_has_event = 1 ;
}
sub readable {
sysread( $queue_read, my $buf, 10 ) ;
- $queue_is_marked = 0 ;
+ $queue_has_event = 0 ;
# Stem::Event::Plain::process_queue();
Stem::Event::Signal::process_signal_queue();
View
9 lib/Stem/Event/Signal.pm
@@ -32,7 +32,8 @@ sub _build {
$SIG{ $signal } = $cached_handlers{$signal} ||=
sub {
- mark_not_empty() ;
+ Stem::Event::Queue::queue_has_event() ;
+
#print "HIT $signal\n";
push @signal_queue, $signal
} ;
@@ -42,6 +43,12 @@ sub _build {
$signal2event{$signal} = $self ;
#print "$signal = $SIG{ $signal }\n" ;
+
+# make sure the event queue is set up so we can handle signals in the
+# event loop
+
+ Stem::Event::Queue::_init_event_queue() ;
+
return ;
}
View
9 t/event/event_test.pl
@@ -11,8 +11,7 @@ BEGIN
use strict ;
-#use Test::More tests => 29 ;
-use Test::More tests => 24 ;
+use Test::More tests => 27 ;
use Symbol ;
@@ -27,9 +26,9 @@ BEGIN
sub test_events {
-# test_null_events() ;
-# test_plain_events () ;
-# test_signal_events () ;
+ test_null_events() ;
+ test_plain_events () ;
+ test_signal_events () ;
test_hard_timer_events () ;
test_soft_timer_events () ;
test_io_events () ;
Please sign in to comment.
Something went wrong with that request. Please try again.