]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/common.perl
tests: add tcp_connect() helper
[public-inbox.git] / t / common.perl
index 91d65c5fa380a41b47420993198a57dfada4bc6d..ccc7be46099aaa7708cb65126d3400b98102a87a 100644 (file)
@@ -1,10 +1,11 @@
-# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
 use POSIX qw(dup2);
 use strict;
 use warnings;
+use IO::Socket::INET;
 
 sub stream_to_string {
        my ($res) = @_;
@@ -38,6 +39,18 @@ sub unix_server ($) {
        $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;
+}
+
 sub spawn_listener {
        my ($env, $cmd, $socks) = @_;
        my $pid = fork;