Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed two small inconsistencies
  • Loading branch information
kraih committed Apr 5, 2012
1 parent c6d0c24 commit 85c4a64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
44 changes: 23 additions & 21 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -35,14 +35,13 @@ sub client {
my $self = shift;
$self = $self->singleton unless ref $self;
my $cb = pop;
my $args = ref $_[0] ? $_[0] : {@_};

# Make sure garbage gets collected
$self->_cleaner;

# New client
my $client = $self->client_class->new;
my $id = $args->{id} || $self->_id;
my $id = $self->_id;
my $c = $self->{connections}->{$id} ||= {};
$c->{client} = $client;
weaken $client->reactor($self->reactor)->{reactor};
Expand All @@ -57,7 +56,7 @@ sub client {
my $c = $self->{connections}->{$id};
delete $c->{client};
my $stream = $c->{stream} = $self->stream_class->new($handle);
$self->stream($stream => $id);
$self->_stream($stream => $id);

# Connected
$self->$cb(undef, $stream);
Expand All @@ -71,7 +70,7 @@ sub client {
);

# Connect
$client->connect($args);
$client->connect(@_);

return $id;
}
Expand Down Expand Up @@ -181,25 +180,13 @@ sub stream {
# Make sure garbage gets collected
$self->_cleaner;

# Find stream for id
my $stream = shift;
unless (blessed $stream) {
return unless my $c = $self->{connections}->{$stream};
return $c->{stream};
}

# Connect stream with reactor
my $id = shift || $self->_id;
my $c = $self->{connections}->{$id} ||= {};
$c->{stream} = $stream;
weaken $stream->reactor($self->reactor)->{reactor};

# Events
weaken $self;
$stream->on(close => sub { $self->{connections}->{$id}->{finish} = 1 });
$stream->start;
my $stream = shift;
return $self->_stream($stream, $self->_id) if blessed $stream;

return $id;
# Find stream for id
return unless my $c = $self->{connections}->{$stream};
return $c->{stream};
}

sub timer {
Expand Down Expand Up @@ -285,6 +272,21 @@ sub _remove {
}
}

sub _stream {
my ($self, $stream, $id) = @_;

# Connect stream with reactor
$self->{connections}->{$id}->{stream} = $stream;
weaken $stream->reactor($self->reactor)->{reactor};

# Events
weaken $self;
$stream->on(close => sub { $self->{connections}->{$id}->{finish} = 1 });
$stream->start;

return $id;
}

1;
__END__
Expand Down
8 changes: 5 additions & 3 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -247,10 +247,11 @@ sub _connect_proxy {
$old->req->proxy(undef);
my $loop = $self->_loop;
my $handle = $loop->stream($id)->steal_handle;
my $c = delete $self->{connections}->{$id};
$loop->remove($id);
weaken $self;
return $loop->client(
$id = $loop->client(
handle => $handle,
id => $id,
timeout => $self->connect_timeout,
tls => 1,
tls_ca => $self->ca,
Expand All @@ -264,10 +265,11 @@ sub _connect_proxy {
$self->_events($stream, $id);

# Start real transaction
$old->connection($tx->connection);
$old->connection($id);
$self->_start($old, $cb);
}
);
return $self->{connections}->{$id} = $c;
}

# Start real transaction
Expand Down

0 comments on commit 85c4a64

Please sign in to comment.