AnyEvent-MPRPC

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

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
Revision history for Perl extension AnyEvent::MPRPC
 
0.20 2013-02-01T21:28:13
 
    - Add 2 callbacks (before/after_connect) and 1 option (connect_timeout)
      (hirose31)
 
0.19
 
    - Split AnyEvent::MessagePack to it's own distribution.
      (tokuhirom)
 
0.18
 
    - AnyEvent::MPRPC::Client 'call' method can take scalar as RPC parameters
      (It has been able to take only ArrayRef).
 
0.17
 
    commit 4f6db620d1b0b86f776946f4d8688dc9fc69c966
    Author: Maxime Soulé <btik-git@scoubidou.com>
    Date:   Mon Jul 30 10:17:51 2012 +0200
 
        A read_type AnyEvent handler must call the callback only once per
        call, else one have a risk of memleak by pushing/shifting too many
        "read" callbacks in the read queue.
        And so each read callback should re-arm itself (if needed) in the read
        queue. Using on_read callback to do that is a mistake, as on_read can
        be called several times before a complete messagepack packet is
        received.
 
0.16
 
    - Fixes RT#74518: issue
    Bug #74518 for AnyEvent-MPRPC: AnyEvent::MessagePack read type corrupts responses
    (fixed By Max++, and reported by asguthrie++)

lib/AnyEvent/MPRPC/Client.pm  view on Meta::CPAN

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
has _next_id => (
    is      => 'ro',
    isa     => 'CodeRef',
    lazy    => 1,
    default => sub {
        my $id = 0;
        sub { ++$id };
    },
);
 
has _callbacks => (
    is      => 'ro',
    isa     => 'HashRef',
    lazy    => 1,
    default => sub { +{} },
);
 
has _connection_guard => (
    is  => 'rw',
    isa => 'Object',
);

lib/AnyEvent/MPRPC/Client.pm  view on Meta::CPAN

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
    ];
 
    if ($self->handler) {
        $self->handler->push_write( msgpack => $request );
    }
    else {
        push @{ $self->_request_pool }, $request;
    }
 
    # $msgid is stringified, but $request->{MP_RES_MSGID] is still IV
    $self->_callbacks->{ $msgid } = AnyEvent->condvar;
}
 
sub _handle_response_cb {
    my $self = shift;
 
    weaken $self;
 
    return sub {
        $self || return;
 
        my ($handle, $res) = @_;
 
        my $d = delete $self->_callbacks->{ $res->[MP_RES_MSGID] };
 
        if (my $error = $res->[MP_RES_ERROR]) {
            if ($d) {
                $d->croak($error);
            } else {
                Carp::croak($error);
            }
        }
 
        $handle->unshift_read(msgpack => $self->_handle_response_cb);

lib/AnyEvent/MPRPC/Server.pm  view on Meta::CPAN

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    isa     => 'HashRef',
    default => sub { {} },
);
 
has _handlers => (
    is      => 'ro',
    isa     => 'ArrayRef',
    default => sub { [] },
);
 
has _callbacks => (
    is      => 'ro',
    isa     => 'HashRef',
    lazy    => 1,
    default => sub { {} },
);
 
no Any::Moose;
 
sub BUILD {
    my $self = shift;

lib/AnyEvent/MPRPC/Server.pm  view on Meta::CPAN

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        $handle->unshift_read(msgpack => $self->_dispatch_cb($indicator));
 
        $self->_handlers->[ fileno($fh) ] = $handle;
    }) unless defined $self->server;
    weaken $self;
 
    $self;
}
 
sub reg_cb {
    my ($self, %callbacks) = @_;
 
    while (my ($method, $callback) = each %callbacks) {
        $self->_callbacks->{ $method } = $callback;
    }
}
 
sub _dispatch_cb {
    my ($self, $indicator) = @_;
 
    weaken $self;
 
    return sub {
        $self || return;
 
        my ($handle, $request) = @_;
        $self->on_dispatch->($indicator, $handle, $request);
        return if $handle->destroyed;
 
        $handle->unshift_read(msgpack => $self->_dispatch_cb($indicator));
 
        return unless $request and ref $request eq 'ARRAY';
 
        my $target = $self->_callbacks->{ $request->[MP_REQ_METHOD] };
 
        my $id = $request->[MP_REQ_MSGID];
        $indicator = "$indicator:$id";
 
        my $res_cb = sub {
            my $type   = shift;
            my $result = @_ > 1 ? \@_ : $_[0];
 
            $handle->push_write( msgpack => [
                MP_TYPE_RESPONSE,

lib/AnyEvent/MPRPC/Server.pm  view on Meta::CPAN

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
=item on_accept => $cb->($fh, $host, $port)
 
=item on_dispatch => $cb->($indicator, $handle, $request);
 
=item handler_options => 'HashRef'
 
Hashref options of L<AnyEvent::Handle> that is used to handle client connections.
 
=back
 
=head2 reg_cb (%callbacks)
 
Register MessagePack RPC methods.
 
    $server->reg_cb(
        echo => sub {
            my ($res_cv, @params) = @_;
            $res_cv->result(@params);
        },
        sum => sub {
            my ($res_cv, @params) = @_;



( run in 0.244 second using v1.01-cache-2.11-cpan-8d75d55dd25 )