forked from kazuho/p5-Server-Starter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for unix sockets with --path option
- Loading branch information
Showing
5 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#! /usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use lib qw(blib/lib lib); | ||
|
||
use IO::Socket::UNIX; | ||
use Server::Starter qw(server_ports); | ||
|
||
my $listener = IO::Socket::UNIX->new() | ||
or die "failed to create unix socket:$!"; | ||
$listener->fdopen((values %{server_ports()})[0], 'w') | ||
or die "failde to bind to listening socket:$!"; | ||
|
||
while (1) { | ||
if (my $conn = $listener->accept) { | ||
while ($conn->sysread(my $buf, 1048576) > 0) { | ||
$conn->syswrite($buf); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use File::Temp (); | ||
use IO::Socket::UNIX; | ||
use Test::More tests => 3; | ||
use Test::SharedFork; | ||
|
||
use Server::Starter qw(start_server); | ||
|
||
$SIG{PIPE} = sub {}; | ||
|
||
my $sockfile = File::Temp::tmpnam(); | ||
|
||
my $pid = fork; | ||
die "fork failed: $!" | ||
unless defined $pid; | ||
if ($pid == 0) { | ||
# child | ||
start_server( | ||
path => $sockfile, | ||
exec => [ $^X, qw(t/03-starter-unix-echod.pl) ], | ||
); | ||
exit 0; | ||
} else { | ||
# parent | ||
sleep 1 | ||
until -e $sockfile; | ||
my $sock = IO::Socket::UNIX->new( | ||
Peer => $sockfile, | ||
) or die "failed to connect to unix socket:$!"; | ||
is $sock->syswrite('hello', 5), 5, 'write'; | ||
is $sock->sysread(my $buf, 5), 5, 'read length'; | ||
is $buf, 'hello', 'read data'; | ||
kill 'TERM', $pid; | ||
} | ||
|
||
unlink $sockfile; |