NAME

Reflex::Connector - Connect to a server without blocking.

VERSION

version 0.010

SYNOPSIS

This is an incomplete excerpt from Reflex::Client. See that module's source for a more complete example.

package SomeKindaClient;
use Moose;
extends 'Reflex::Connector';

sub on_connector_success {
	my ($self, $args) = @_;

	# Do something with $arg->{socket} here.
}

sub on_connector_failure {
	my ($self, $args) = @_;
	warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";
	$self->stop();
}

Reflex objects may also be used in condvar-like ways. This excerpts from eg/eg-38-promise-client.pl in the distribution.

my $connector = Reflex::Connector->new(remote_port => 12345);
my $event = $connector->wait();

if ($event->{name} eq "failure") {
	eg_say("connection error $event->{arg}{errnum}: $event->{arg}{errstr}");
	exit;
}

eg_say("Connected.");
# Do something with $event->{arg}{socket}.

DESCRIPTION

Reflex::Connector performs a non-blocking connect() object on a plain socket. It extends Reflex::Handle to wait for the connection without blocking the rest of a program.

By default, it will create its own TCP socket. A program can provide a specially prepared socket via the inherited "handle" attribute.

Two other attributes, "remote_addr" and "remote_port" specify where to connect the socket.

This connector was written with TCP in mind, but it's intended to also be useful for other connected sockets.

Attributes

Reflex::Connector supplies its own attributes in addition to those provided by Reflex::Handle.

remote_addr

The "remote_addr" attribute specifies the address of a remote server. It defaults to "127.0.0.1".

remote_port

The "remote_port" attribute sets the port of the server to which it will attempt a connection. The remote port may be an integer or the symbolic port name from /etc/services.

Methods

Reflex::Connector inherits its methods from Reflex::Handle. It doesn't add new methods at this time.

Events

Reflex::Connector emits some events, which may be mapped to a subclass' methods, or to handlers in a container object. Please see Reflex and Reflex::Callbacks for more information.

failure

Revlex::Connector emits a "failure" event if it can't establish a connection. Failure events include a few, fairly standard parameters:

  • socket - Undefined, since a connection could not be made.

  • errnum - The numeric value of $! at the time of error.

  • errstr - The string value of $! at the time of error.

  • errfun - A brief description of the function call that failed.

success

The "success" event is emitted if a connection has been established. It will return a "socket", the value of which is the connected socket.

EXAMPLES

Reflex::Client extends Reflex::Connector to include a Reflex::Stream when the socket is connected.

eg/eg-38-promise-client.pl shows how to use Reflex::Connector in a condvar-like fashion.

SEE ALSO

Reflex Reflex::Client

"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex