Skip to content

Commit

Permalink
smaller methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 10, 2014
1 parent af380c0 commit 140a273
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -81,6 +81,26 @@ sub stop {
return $self;
}

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

my $c = $self->{connections}{$id} = {tls => $tls};
warn "-- Accept (@{[$stream->handle->peerhost]})\n" if DEBUG;
$stream->timeout($self->inactivity_timeout);

$stream->on(close => sub { $self->_close($id) });
$stream->on(
error => sub {
return unless $self;
$self->app->log->error(pop);
$self->_close($id);
}
);
$stream->on(read => sub { $self->_read($id => pop) });
$stream->on(timeout =>
sub { $self->app->log->debug('Inactivity timeout.') if $c->{tx} });
}

sub _build_tx {
my ($self, $id, $c) = @_;

Expand Down Expand Up @@ -175,27 +195,8 @@ sub _listen {
my $tls = $options->{tls} = $url->protocol eq 'https';

weaken $self;
push @{$self->acceptors}, $self->ioloop->server(
$options => sub {
my ($loop, $stream, $id) = @_;

my $c = $self->{connections}{$id} = {tls => $tls};
warn "-- Accept (@{[$stream->handle->peerhost]})\n" if DEBUG;
$stream->timeout($self->inactivity_timeout);

$stream->on(close => sub { $self->_close($id) });
$stream->on(
error => sub {
return unless $self;
$self->app->log->error(pop);
$self->_close($id);
}
);
$stream->on(read => sub { $self->_read($id => pop) });
$stream->on(timeout =>
sub { $self->app->log->debug('Inactivity timeout.') if $c->{tx} });
}
);
push @{$self->acceptors},
$self->ioloop->server($options => sub { shift; $self->_accept($tls, @_) });

return if $self->silent;
$self->app->log->info(qq{Listening at "$url".});
Expand Down

0 comments on commit 140a273

Please sign in to comment.