Permalink
Browse files

removed Mojo::IOLoop::Resolver

  • Loading branch information...
kraih committed Nov 16, 2011
1 parent ca79cff commit 6c205e484e09336ef3d78dbc78768d80daca6b17
View
@@ -8,9 +8,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Deprecated Mojo::IOLoop->write in favor of
Mojo::IOLoop::Stream->write.
- Deprecated on_* methods in Mojo::IOLoop.
- Replaced servers method in Mojo::IOLoop::Resolver with servers
attribute.
- Added EXPERIMENTAL hosts attribute to Mojo::IOLoop::Resolver.
- Removed Mojo::IOLoop::Resolver.
- Added EXPERIMENTAL is_readable method to Mojo::IOLoop::Stream.
- Added EXPERIMENTAL charset method to Mojo::Content.
- Added EXPERIMENTAL write event to Mojo::IOLoop::Stream.
View
@@ -4,7 +4,6 @@ use Mojo::Base -base;
use Carp 'croak';
use Mojo::IOLoop::Client;
use Mojo::IOLoop::Delay;
use Mojo::IOLoop::Resolver;
use Mojo::IOLoop::Server;
use Mojo::IOLoop::Stream;
use Mojo::IOWatcher;
@@ -24,11 +23,6 @@ has iowatcher => sub {
has [qw/cleanup_interval max_accepts/] => 0;
has max_connections => 1000;
has [qw/on_lock on_unlock/];
has resolver => sub {
my $resolver = Mojo::IOLoop::Resolver->new(ioloop => shift);
weaken $resolver->{ioloop};
return $resolver;
};
has server_class => 'Mojo::IOLoop::Server';
has stream_class => 'Mojo::IOLoop::Stream';
@@ -46,8 +40,8 @@ sub client {
my $id = $args->{id} || $self->_id;
my $c = $self->{connections}->{$id} ||= {};
$c->{client} = $client;
$client->resolver($self->resolver);
weaken $client->{resolver};
$client->iowatcher($self->iowatcher);
weaken $client->{iowatcher};
# Events
weaken $self;
@@ -589,14 +583,6 @@ Note that exceptions in this callback are not captured.
A callback to free the accept lock, used to sync multiple server processes.
Note that exceptions in this callback are not captured.
=head2 C<resolver>
my $resolver = $loop->resolver;
$loop = $loop->resolver(Mojo::IOLoop::Resolver->new);
DNS stub resolver, usually a L<Mojo::IOLoop::Resolver> object.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<server_class>
my $class = $loop->server_class;
View
@@ -2,7 +2,6 @@ package Mojo::IOLoop::Client;
use Mojo::Base 'Mojo::EventEmitter';
use IO::Socket::INET;
use Mojo::IOLoop::Resolver;
use Scalar::Util 'weaken';
use Socket qw/IPPROTO_TCP SO_ERROR TCP_NODELAY/;
@@ -18,38 +17,30 @@ use constant TLS => $ENV{MOJO_NO_TLS}
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0;
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;
has resolver => sub { Mojo::IOLoop::Resolver->new };
# "It's like my dad always said: eventually, everybody gets shot."
has iowatcher => sub {
require Mojo::IOLoop;
Mojo::IOLoop->singleton->iowatcher;
};
sub DESTROY {
my $self = shift;
return if $self->{connected};
$self->_cleanup;
}
# "I wonder where Bart is, his dinner's getting all cold... and eaten."
sub connect {
my $self = shift;
my $args = ref $_[0] ? $_[0] : {@_};
$args->{address} ||= 'localhost';
# Connect
return $self->resolver->ioloop->timer(0 => sub { $self->_connect($args) })
unless !$args->{handle} && (my $address = $args->{address});
# Lookup
$self->resolver->lookup(
$address => sub {
$args->{address} = $_[1] || $args->{address};
$self->_connect($args);
}
);
weaken $self;
$self->iowatcher->timer(0 => sub { $self->_connect($args) });
}
sub _cleanup {
my $self = shift;
return unless my $resolver = $self->{resolver};
return unless my $loop = $resolver->ioloop;
return unless my $watcher = $loop->iowatcher;
return unless my $watcher = $self->{iowatcher};
$watcher->drop_timer($self->{timer}) if $self->{timer};
$watcher->drop_handle($self->{handle}) if $self->{handle};
}
@@ -59,7 +50,7 @@ sub _connect {
# New socket
my $handle;
my $watcher = $self->resolver->ioloop->iowatcher;
my $watcher = $self->iowatcher;
my $timeout = $args->{timeout} || 3;
unless ($handle = $args->{handle}) {
my %options = (
@@ -131,7 +122,7 @@ sub _connecting {
# Switch between reading and writing
my $handle = $self->{handle};
my $watcher = $self->resolver->ioloop->iowatcher;
my $watcher = $self->iowatcher;
if ($self->{tls} && !$handle->connect_SSL) {
my $error = $IO::Socket::SSL::SSL_ERROR;
if ($error == TLS_READ) { $watcher->change($handle, 1, 0) }
@@ -201,12 +192,13 @@ Emitted if an error happens on the connection.
L<Mojo::IOLoop::Client> implements the following attributes.
=head2 C<resolver>
=head2 C<iowatcher>
my $resolver = $client->resolver;
$client = $client->resolver(Mojo::IOLoop::Resolver->new);
my $watcher = $client->iowatcher;
$client = $client->iowatcher(Mojo::IOWatcher->new);
DNS stub resolver, defaults to a L<Mojo::IOLoop::Resolver> object.
Low level event watcher, defaults to the C<iowatcher> attribute value of the
global L<Mojo::IOLoop> singleton.
=head1 METHODS
View
@@ -18,6 +18,8 @@ sub end {
$self->emit_safe('finish', @{$self->{args}}) if --$self->{counter} <= 0;
}
# "Mrs. Simpson, bathroom is not for customers.
# Please use the crack house across the street."
sub wait {
my $self = shift;
$self->once(finish => sub { shift->ioloop->stop });
@@ -91,8 +93,8 @@ Increment active event counter, the returned callback can be used instead of
C<end>.
my $delay = Mojo::IOLoop->delay;
Mojo::IOLoop->resolver->lookup('mojolicio.us' => $delay->begin);
my $address = $delay->wait;
Mojo::UserAgent->new->get('mojolicio.us' => $delay->begin);
my $tx = $delay->wait;
=head2 C<end>
Oops, something went wrong.

0 comments on commit 6c205e4

Please sign in to comment.