1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#-----------------------------------------------------------------------
# Copyright (C) 2005-2015 by Jörn Reder <joern AT zyn.de>.
# All Rights Reserved. See file COPYRIGHT for details.
#
# This module is part of Event::RPC, which is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#-----------------------------------------------------------------------
package Event::RPC::Loop::Event;
use base qw( Event::RPC::Loop );
use strict;
use utf8;
use Event;
sub add_io_watcher {
my $self = shift;
my %par = @_;
my ($fh, $cb, $desc, $poll) = @par{'fh','cb','desc','poll'};
return Event->io (
fd => $fh,
poll => $poll,
cb => $cb,
desc => $desc,
reentrant => 0,
parked => 0,
);
}
sub del_io_watcher {
my $self = shift;
my ($watcher) = @_;
$watcher->cancel;
1;
}
sub add_timer {
my $self = shift;
my %par = @_;
my ($interval, $after, $cb, $desc) =
@par{'interval','after','cb','desc'};
die "interval and after can't be used together"
if $interval && $after;
return Event->timer (
interval => $interval,
after => $after,
cb => $cb,
desc => $desc,
);
}
sub del_timer {
my $self = shift;
my ($timer) = @_;
$timer->cancel;
1;
}
sub enter {
my $self = shift;
Event::loop();
1;
}
sub leave {
my $self = shift;
Event::unloop_all("ok");
1;
}
1;
__END__
=encoding utf8
=head1 NAME
Event::RPC::Loop::Event - Event mainloop for Event::RPC
=head1 SYNOPSIS
use Event::RPC::Server;
use Event::RPC::Loop::Event;
my $server = Event::RPC::Server->new (
...
loop => Event::RPC::Loop::Event->new(),
...
);
$server->start;
=head1 DESCRIPTION
This modules implements a mainloop using the Event module
for the Event::RPC::Server module. It implements the interface
of Event::RPC::Loop. Please refer to the manpage of
Event::RPC::Loop for details.
=head1 AUTHORS
Jörn Reder <joern AT zyn.de>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2005-2015 by Jörn Reder <joern AT zyn.de>.
This library is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.
=cut
|