+sub tcp_server () {
+ IO::Socket::INET->new(
+ LocalAddr => '127.0.0.1',
+ ReuseAddr => 1,
+ Proto => 'tcp',
+ Type => Socket::SOCK_STREAM(),
+ Listen => 1024,
+ Blocking => 0,
+ )
+}
+
+sub unix_server ($) {
+ my $s = IO::Socket::UNIX->new(
+ Listen => 1024,
+ Type => Socket::SOCK_STREAM(),
+ Local => $_[0],
+ );
+ $s->blocking(0);
+ $s;
+}
+
+sub tcp_connect {
+ my ($dest, %opt) = @_;
+ my $s = IO::Socket::INET->new(
+ Proto => 'tcp',
+ Type => Socket::SOCK_STREAM(),
+ PeerAddr => $dest->sockhost . ':' . $dest->sockport,
+ %opt,
+ );
+ $s->autoflush(1);
+ $s;
+}
+