AnyEvent-Handle-ZeroMQ

 view release on metacpan or  search on metacpan

lib/AnyEvent/Handle/ZeroMQ.pm  view on Meta::CPAN

    while( $socket->getsockopt(ZMQ_EVENTS) & ZMQ_POLLOUT && @$wqueue ) {
	my $msgs = shift @$wqueue;
	while( defined( my $msg = shift @$msgs ) ) {
	    $socket->send($msg, @$msgs ? ZMQ_SNDMORE : 0);
	}

	$write_something = 1;
    }

    $self->[ON_DRAIN]($self) if( !@$wqueue && $write_something && $self->[ON_DRAIN] );
}

sub push_write {
    my $self = shift;
    push @{$self->[WQUEUE]}, shift;
    _consume_write($self);
}

if( !exists(&ZeroMQ::Socket::DESTROY) ) {
    *ZeroMQ::Socket::DESTROY = sub {
	my $self = shift;
	eval { $self->close };
    };
}

=head2 old_cb = on_drain( cb(hdl) )

=cut

sub on_drain {
    my $self = shift;
    my $cb = pop;

    $cb->($self) if( $cb && !@{$self->[WQUEUE]} );

    my $old_cb = $self->[ON_DRAIN];
    $self->[ON_DRAIN] = $cb;

    return $old_cb;
}

=head2 old_cb = on_error( cb(hdl) )

=cut

sub on_error {
    my $self = shift;
    my $cb = pop;

    my $old_cb = $self->[ON_ERROR];
    $self->[ON_ERROR] = $cb;

    return $old_cb;
}

=head1 DIFFERENCES

There is also a module called L<AnyEvent::ZeroMQ> in CPAN.

AnyEvent::ZeroMQ::* is a huge, heavy,
and full-functioned framework, but this module is a simple,
lightweight library with less dependency, and runs faster.

So this module is only occupy a smaller namespace
under AnyEvent::Handle::

This module and AnyEvent::ZeroMQ::* are not replacable to each other.

=head1 AUTHOR

Cindy Wang (CindyLinz)

=head1 BUGS

Please report any bugs or feature requests to C<bug-anyevent-handle-zeromq at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-Handle-ZeroMQ>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc AnyEvent::Handle::ZeroMQ


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker (report bugs here)

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-Handle-ZeroMQ>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/AnyEvent-Handle-ZeroMQ>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/AnyEvent-Handle-ZeroMQ>

=item * Search CPAN

L<http://search.cpan.org/dist/AnyEvent-Handle-ZeroMQ/>

=back


=head1 ACKNOWLEDGEMENTS


=head1 LICENSE AND COPYRIGHT

Copyright 2011 Cindy Wang (CindyLinz).

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.



( run in 0.558 second using v1.01-cache-2.11-cpan-df04353d9ac )