Hi,

Using CPAN source of perl-5.14.2 in Windows 7, I am trying following code using socketpair to communicate between two process. The data is properly being communicated but the socket on spawned process (testchild.pl) act in blocking mode using sysread(..) irrespective of forcing it to non-blocking. I could confirm that the socket is properly set to non-blocking based on the return value from ioctlsocket(..). If I replace sysread(..) with recv(..) in testchild.pl, I receive EWOULDBLOCK as expected. Any idea what's going wrong with sysread(..) and how to make this to work with sysread(..)?

# testparent.pl use Win32API::File; use IO::Handle; use Symbol qw(gensym); use IO::Socket; use Win32::Process; sub win32_spawn_child { my $program = shift; my $cmd = shift; my $inherit = shift; if( ! Win32::Process::Create($last_process, $program, $cmd, $inherit +, &CREATE_NO_WINDOW, ".") ) { print "$^E\n"; return 0; } my $pid = $last_process->GetProcessID() || do { print "$^E\n"; }; return $pid; } my ($child_socket, $parent_socket); socketpair($child_socket, $parent_socket, Socket::AF_UNIX, Socket::SOCK_STREAM, Socket::PF_UNSPEC +) or die "Unable to create socketpair for transfer agent: $!"; $child_socket->autoflush(1); $parent_socket->autoflush(1); my $perl = "c:\\perl-5.14.2\\bin\\perl.exe"; my $handle = Win32API::File::GetOsFHandle($parent_socket); my $handle1 = Win32API::File::GetOsFHandle($child_socket); print syswrite($child_socket, "abcdef\n"), "\n"; win32_spawn_child($perl, "$perl c:\\temp\\JOBCON-2902\\testchild.pl $h +andle $handle1", 1); close $parent_socket; $child_socket->blocking(1); my $buf; my $bytes_read = sysread($child_socket, $buf, 1024); print $buf, "\n"; exit 0;
# testchild.pl use IO::Socket; use Win32API::File; use Symbol qw(gensym); my $buf; my $handle = gensym(); my $handle1 = gensym(); Win32API::File::OsFHandleOpen($handle, $ARGV[0], "rw"); Win32API::File::OsFHandleOpen($handle1, $ARGV[1], "rw"); $handle1->close(); $handle = IO::Socket->new_from_fd($handle, "r+"); $handle->blocking(0); #while (defined (my $bytes_read = sysread($handle, $buf, 1024))) { while (defined (my $bytes_read = recv($handle, $buf, 1024, 0))) { if($bytes_read) { open FILE, ">> debug.txt"; print FILE $bytes_read, "\n"; print FILE $buf, "\n"; close FILE; } else { open FILE, ">> debug.txt"; print FILE "eof\n"; close FILE; exit 0; } } if( $! == 10035 ) { open FILE, ">> debug.txt"; print FILE "ewouldblock", "\n"; close FILE; } print syswrite($handle, "abcdef\n"), "\n"; exit 0;

-Karthik


In reply to Issues in using socketpair in Windows by kartlee05

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.