Skip to content

Commit

Permalink
Use Net::Async::ZMQ instead of IO::Async::Handle
Browse files Browse the repository at this point in the history
This moves the specific handling of the ZMQ file descriptors into
Net::Async::ZMQ where it can handle things in a more cross-platform
manner.

This is related to
<#1>,
<#41>.
  • Loading branch information
zmughal committed Dec 17, 2017
1 parent 56938b4 commit 5384fe9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ requires 'MooX::HandlesVia';
requires 'MooX::Singleton';
requires 'MooX::Types::MooseLike::Base';
requires 'MooseX::HandlesConstructor';
requires 'Net::Async::ZMQ';
requires 'Net::Async::ZMQ::Socket';
requires 'PPI::Document';
requires 'Path::Class';
requires 'Reply';
Expand Down
19 changes: 12 additions & 7 deletions lib/Devel/IPerl/Kernel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use IO::Async::Loop;
use IO::Async::Handle;
use IO::Handle;
use IO::Async::Routine;
use Net::Async::ZMQ;
use Net::Async::ZMQ::Socket;
use Devel::IPerl::Kernel::Callback::REPL;
use Devel::IPerl::Message::ZMQ;

Expand Down Expand Up @@ -177,7 +179,6 @@ sub _assign_ports_from_data {
#}}}
#}}}

my @io_handles;
sub run {#{{{
my ($self) = @_;
STDOUT->autoflush(1);
Expand All @@ -188,13 +189,14 @@ sub run {#{{{

$self->_setup_heartbeat;

my $zmq = Net::Async::ZMQ->new;

my @socket_funcs = ( \&shell, \&control, \&stdin, \&iopub );
for my $socket_fn (@socket_funcs) {
my $socket = $self->$socket_fn();
my $socket_fd = zmq_getsockopt( $socket, ZMQ_FD );
my $io_handle = IO::Handle->new_from_fd( $socket_fd, 'r' );
my $handle = IO::Async::Handle->new(
handle => $io_handle,

my $async_socket = Net::Async::ZMQ::Socket->new(
socket => $socket,
on_read_ready => sub {
my @blobs;
while ( my $recvmsg = zmq_recvmsg( $socket, ZMQ_RCVMORE ) ) {
Expand All @@ -206,10 +208,13 @@ sub run {#{{{
$self->route_message(\@blobs, $socket);
}
},
on_write_ready => sub { },
);
$self->_loop->add( $handle );

$zmq->add_child( $async_socket );
}

$self->_loop->add( $zmq );

$self->_loop->loop_forever;
}

Expand Down

0 comments on commit 5384fe9

Please sign in to comment.