Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/RPC/Switch/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use Encode qw(encode_utf8 decode_utf8);
use File::Basename;
use IO::Handle;
use POSIX ();
use Scalar::Util qw(blessed refaddr);
use Scalar::Util qw(blessed refaddr weaken);
use Storable;
use Sys::Hostname;

Expand Down Expand Up @@ -91,7 +91,7 @@ sub new {
}

sub connect {
my $self = shift;
weaken (my $self = shift);

delete $self->ioloop->{__exit__};
delete $self->{auth};
Expand Down Expand Up @@ -133,13 +133,13 @@ sub connect {
$self->{auth} = 0;
return;
}
my $ns = MojoX::NetstringStream->new(stream => $stream);
$self->{ns} = $ns;
my $conn = $rpc->newconnection(
$self->{ns} = MojoX::NetstringStream->new(stream => $stream);
weaken (my $ns = $self->{ns});
$self->{conn} = $rpc->newconnection(
owner => $self,
write => sub { $ns->write(@_) },
);
$self->{conn} = $conn;
weaken (my $conn = $self->{conn});
$ns->on(chunk => sub {
my ($ns2, $chunk) = @_;
#say 'got chunk: ', $chunk;
Expand Down Expand Up @@ -535,6 +535,7 @@ sub rpc_ping {
sub _magic {
#say '_magic: ', Dumper(\@_);
my ($self, $action, $con, $request, $rpccb) = @_;
weaken $con;
my $method = $request->{method};
my $req_id = $request->{id};
unless ($action) {
Expand Down Expand Up @@ -626,6 +627,8 @@ sub _magic {
sub _subproc {
my ($self, $cb, $action, $req_id, @args) = @_;

weaken $self;

# based on Mojo::IOLoop::Subprocess
my $ioloop = $self->ioloop;

Expand Down