Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions perl/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ MANIFEST.SKIP
README
t/01-load.t
t/02-unix_domain_socket.t
t/03-network_socket.t
typemap
10 changes: 1 addition & 9 deletions perl/t/02-unix_domain_socket.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bSocket\b/) {
} elsif (! $can_fork) {
plan skip_all => 'no fork';
} elsif ($^O eq 'MSWin32') {
if ($ENV{CONTINUOUS_INTEGRATION}) {
# https://github.com/Perl/perl5/issues/17429
plan skip_all => 'Skipping on Windows CI';
} else {
# https://github.com/Perl/perl5/issues/17575
if (! eval { socket(my $sock, PF_UNIX, SOCK_STREAM, 0) }) {
plan skip_all => "AF_UNIX unavailable or disabled on this platform"
}
}
plan skip_all => "FCGI with UNIX domain sockets not implemented on $^O";
}

my (undef, $unix_socket_file) = tempfile();
Expand Down
59 changes: 59 additions & 0 deletions perl/t/03-network_socket.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env perl

use strict;
use warnings;

use FCGI;
use FCGI::Client;
use IO::Socket::IP;
use Test::More 'tests' => 4;

my $port = 8888;

# Client
if (my $pid = fork()) {
my $right_ret = <<'END';
Content-Type: text/plain

END

my ($stdout, $stderr) = client_request($port);
is($stdout, $right_ret."0\n", 'Test first round on stdout.');
is($stderr, undef, 'Test first round on stderr.');

($stdout, $stderr) = client_request($port);
is($stdout, $right_ret."1\n", 'Test second round on stdout.');
is($stderr, undef, 'Test second round on stderr.');

# Server
} elsif (defined $pid) {
my $fcgi_socket = FCGI::OpenSocket(':'.$port, 5);
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $fcgi_socket);

# Only two cycles.
my $count = 0;
while ($count < 2 && $request->Accept() >= 0) {
print "Content-Type: text/plain\n\n";
print $count++."\n";
}
exit;

} else {
die $!;
}

sub client_request {
my $port = shift;

my $sock = IO::Socket::IP->new(
PeerAddr => '127.0.0.1',
PeerPort => $port,
) or die $!;

my $client = FCGI::Client::Connection->new(sock => $sock);
my ($stdout, $stderr) = $client->request({
REQUEST_METHOD => 'GET',
}, '');

return ($stdout, $stderr);
}