Net::Proxy::Connector::tcp - Net::Proxy connector for standard tcp proxies


Net-Proxy documentation Contained in the Net-Proxy distribution.

Index


Code Index:

NAME

Top

Net::Proxy::Connector::tcp - Net::Proxy connector for standard tcp proxies

SYNOPSIS

Top

    # sample proxy using Net::Proxy::Connector::tcp
    use Net::Proxy;

    my $proxy = Net::Proxy->new(
        in  => { type => tcp, port => '6789' },
        out => { type => tcp, host => 'remotehost', port => '9876' },
    );
    $proxy->register();

    Net::Proxy->mainloop();

DESCRIPTION

Top

Net::Proxy::Connector::tcp is a connector for handling basic, standard TCP connections.

CONNECTOR OPTIONS

Top

The connector accept the following options:

in

* host

The listening address. If not given, the default is localhost.

* port

The listening port.

out

* host

The remote host.

* port

The remote port.

* timeout

The socket timeout for connection (out only).

AUTHOR

Top

Philippe 'BooK' Bruhat, <book@cpan.org>.

COPYRIGHT

Top

LICENSE

Top

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Net-Proxy documentation Contained in the Net-Proxy distribution.

package Net::Proxy::Connector::tcp;
use strict;
use warnings;
use IO::Socket::INET;

use Net::Proxy::Connector;
our @ISA = qw( Net::Proxy::Connector );

sub init {
    my ($self) = @_;

    # set up some defaults
    $self->{host}    ||= 'localhost';
    $self->{timeout} ||= 1;
}

# IN
*listen = \&Net::Proxy::Connector::raw_listen;

*accept_from = \&Net::Proxy::Connector::raw_accept_from;

# OUT
sub connect {
    my ($self) = @_;
    my $sock = IO::Socket::INET->new(
        PeerAddr  => $self->{host},
        PeerPort  => $self->{port},
        Proto     => 'tcp',
        Timeout   => $self->{timeout},
    );
    die $! unless $sock;
    return $sock;
}

# READ
*read_from = \&Net::Proxy::Connector::raw_read_from;

# WRITE
*write_to = \&Net::Proxy::Connector::raw_write_to;

1;

__END__