From: Matt S Trout Date: Tue, 20 Dec 2011 11:57:53 +0000 (+0000) Subject: basic TCP connection support for ConnectorService X-Git-Tag: v0.001002~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=42c84e78e36b4443212d63b179106001f3f15ebf;p=scpubgit%2FTak.git basic TCP connection support for ConnectorService --- diff --git a/lib/Tak/ConnectorService.pm b/lib/Tak/ConnectorService.pm index 50d8a25..3bcf64e 100644 --- a/lib/Tak/ConnectorService.pm +++ b/lib/Tak/ConnectorService.pm @@ -2,6 +2,7 @@ package Tak::ConnectorService; use IPC::Open2; use IO::Socket::UNIX; +use IO::Socket::INET; # Sucks to be v6, see comment where used use IO::All; use Tak::Router; use Tak::Client; @@ -21,7 +22,7 @@ sub handle_create { die [ mistake => "No target supplied to create" ] unless $on; my $log_level = $args{log_level}||'info'; my ($kid_in, $kid_out, $kid_pid) = $self->_open($on, $log_level); - unless ($on =~ /^\.?\//) { + if ($kid_pid) { $kid_in->print($Tak::STDIONode::DATA, "__END__\n") unless $on eq '-'; # Need to get a handshake to indicate STDIOSetup has finished # messing around with file descriptors, otherwise we can severely @@ -54,8 +55,18 @@ sub _open { return ($kid_in, $kid_out, $kid_pid); } elsif ($on =~ /^\.?\//) { # ./foo or /foo my $sock = IO::Socket::UNIX->new($on) - or die "Couldn't open socket ${on}: $!"; - return ($sock, $sock, 'UNIX'); + or die "Couldn't open unix domain socket ${on}: $!"; + return ($sock, $sock, undef); + } elsif ($on =~ /:/) { # foo:80 we hope + # IO::Socket::IP is a better answer. But can pull in XS deps. + # Well, more strictly it pulls in Socket::GetAddrInfo, which can + # actually work without its XS implementation (just doesn't handle v6) + # and I've not properly pondered how to make things like fatpacking + # Just Fucking Work in such a circumstance. First person to need IPv6 + # and be reading this comment, please start a conversation about it. + my $sock = IO::Socket::INET->new(PeerAddr => $on) + or die "Couldn't open TCP socket ${on}: $!"; + return ($sock, $sock, undef); } my $ssh = $self->ssh->{$on} ||= Net::OpenSSH->new($on); $ssh->error and