Common subdirectories: IO-Async-0.70/examples and IO-Async-0.70-sockopt//examples
Common subdirectories: IO-Async-0.70/lib and IO-Async-0.70-sockopt//lib
Common subdirectories: IO-Async-0.70/t and IO-Async-0.70-sockopt//t
Common subdirectories: IO-Async-0.70/lib/IO and IO-Async-0.70-sockopt//lib/IO
Common subdirectories: IO-Async-0.70/lib/IO/Async and IO-Async-0.70-sockopt//lib/IO/Async
Only in IO-Async-0.70-sockopt//lib/IO/Async: .Process.pm.swp
Common subdirectories: IO-Async-0.70/lib/IO/Async/Internals and IO-Async-0.70-sockopt//lib/IO/Async/Internals
Common subdirectories: IO-Async-0.70/lib/IO/Async/Loop and IO-Async-0.70-sockopt//lib/IO/Async/Loop
Common subdirectories: IO-Async-0.70/lib/IO/Async/OS and IO-Async-0.70-sockopt//lib/IO/Async/OS
diff -ru IO-Async-0.70/lib/IO/Async/Process.pm IO-Async-0.70-sockopt//lib/IO/Async/Process.pm
--- IO-Async-0.70/lib/IO/Async/Process.pm Tue Dec 15 13:19:16 2015
+++ IO-Async-0.70-sockopt//lib/IO/Async/Process.pm Tue Jul 12 18:24:31 2016
@@ -14,6 +14,7 @@
use Carp;
use Socket qw( SOCK_STREAM );
+use Data::Dumper;
use Future;
@@ -232,6 +233,14 @@
C<from> parameter will be written to the child. When all of the data has been
written the pipe will be closed.
+=item prefork => CODE
+
+Only valid for via => 'socketpair', this code block runs after the
+C<socketpair(2)> is created, but before the child is forked off. This is handy
+for when you need to use C<setsockopt(3)> to condition both ends of the socket.
+The arguments passed in are the L<IO::Socket> objects for the parent and child
+ends of the socket.
+
=back
=head2 stdin => ...
@@ -355,7 +364,7 @@
}
if( defined $via and $via == FD_VIA_SOCKETPAIR ) {
- $self->{fd_opts}{$fd}{$_} = delete $args{$_} for qw( family socktype );
+ $self->{fd_opts}{$fd}{$_} = delete $args{$_} for qw( family socktype prefork );
}
keys %args and croak "Unexpected extra keys for fd $fd - " . join ", ", keys %args;
@@ -438,6 +447,8 @@
elsif( $via == FD_VIA_SOCKETPAIR ) {
my ( $myfd, $childfd ) = IO::Async::OS->socketpair( $opts->{family}, $opts->{socktype} ) or croak "Unable to socketpair() - $!";
+ $opts->{prefork}->( $myfd, $childfd ) if $opts->{prefork};
+
$handle->configure( handle => $myfd );
if( $key eq "stdio" ) {
@@ -866,6 +877,31 @@
$process->stdin->write( "Here is some more data\n" );
+=head2 Setting socket options
+
+By using the C<prefork> code sub, you can change the socket receive buffer size
+at both ends of the socket before the child is forked (at which point it would
+be too late to change the child end of the socket).
+
+ use Socket qw( SOL_SOCKET SO_RCVBUF );
+
+ my $process = IO::Async::Process->new(
+ command => [ "command-to-read-from-and-write-to", "arguments" ],
+ stdio => {
+ via => "socketpair",
+ prefork => sub {
+ my ($parentfd, $childfd) = @_;
+
+ # Set parent end of socket receive buffer to 3 MB
+ $parentfd->setsockopt(SOL_SOCKET, SO_RCVBUF, 3 * 1024 * 1024);
+ # Set child end of socket receive buffer to 3 MB
+ $childfd ->setsockopt(SOL_SOCKET, SO_RCVBUF, 3 * 1024 * 1024);
+ },
+ },
+ );
+
+ $loop->add( $process );
+
=cut
=head1 AUTHOR
Common subdirectories: IO-Async-0.70/lib/IO/Async/Protocol and IO-Async-0.70-sockopt//lib/IO/Async/Protocol
Common subdirectories: IO-Async-0.70/lib/IO/Async/Timer and IO-Async-0.70-sockopt//lib/IO/Async/Timer
Only in IO-Async-0.70-sockopt//t: .34process-handles.t.swp
diff -ru IO-Async-0.70/t/34process-handles.t IO-Async-0.70-sockopt//t/34process-handles.t
--- IO-Async-0.70/t/34process-handles.t Tue Dec 15 13:19:16 2015
+++ IO-Async-0.70-sockopt//t/34process-handles.t Tue Jul 12 17:41:15 2016
@@ -365,6 +365,48 @@
{
my $process = IO::Async::Process->new(
+ code => sub {
+ defined( recv STDIN, my $pkt, 8192, 0 ) or die "Cannot recv - $!";
+ send STDOUT, $pkt, 0 or die "Cannot send - $!";
+ return 0;
+ },
+ stdio => {
+ via => "socketpair",
+ prefork => sub {
+ my ($myfd, $childfd) = @_;
+
+ $myfd->write("Data from the prefork");
+ },
+ },
+ on_finish => sub { },
+ );
+
+ isa_ok( $process->stdio, "IO::Async::Stream", '$process->stdio isa Stream' );
+
+ my $output_packet = "";
+ $process->stdio->configure(
+ on_read => sub {
+ my ( undef, $buffref ) = @_;
+ $output_packet .= $$buffref;
+ $$buffref = "";
+ return 0;
+ },
+ );
+
+ $loop->add( $process );
+
+ isa_ok( $process->stdio->read_handle, "IO::Socket", '$process->stdio handle isa IO::Socket' );
+
+ wait_for { defined $output_packet and !$process->is_running };
+
+ ok( $process->is_exited, '$process->is_exited after perl STDIO via socketpair' );
+ is( $process->exitstatus, 0, '$process->exitstatus after perl STDIO via socketpair' );
+
+ is_deeply( $output_packet, "Data from the prefork", '$output_packet from prefork via socketpair' );
+}
+
+{
+ my $process = IO::Async::Process->new(
code => sub { return 0 },
stdio => { via => "socketpair", family => "inet" },
on_finish => sub { },