Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Cannot read socket fh in Net::Daemon test

by mnooning (Sexton)
on Feb 16, 2011 at 21:42 UTC ( #888580=perlquestion: print w/ replies, xml ) Need Help??
mnooning has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I took over as maintainer of Net::Daemon a number of years ago because I had a patch for it, because the maintainer at the time could not be found, and because the original author let me know he no longer does this sort of thing. One would have to know both threads and sockets programming, neither of which I actually know, but there was noone else. I need help now for Net::Daemon on Windows. Specifically, with some code in the file Net-Daemon\t\thread.t.

t/thread.t ...... Error while reading 0: 0 () at t/thread.t line 42.

A daemon child is opening up a handle to a port, then writing to it, flushing the handle, and then reading from the same handle. The writing to the handle works. The reading from the handle no longer works. The code used to work. Can anyone take a look at this?

To repeat the results,
  • Download Net-Daemon-0.43 from CPAN
  • tar -xfv the gz file
  • cd to Net-Daemon directory
  • perl Makefile.PL
  • nmake
  • nmake test

The actual code from thread.t that fails is pasted below. The line with "Error while reading ..." is what always prints out. Again, this code always used to work. The $port number is typically in the 3 thousands range.

my($handle, $port) = Net::Daemon::Test->Child ($numTests, $^X, 't/server', '--timeout', 20, '--mode=threads'); print "Making first connection to port $port...\n"; $fh = IO::Socket::INET->new('PeerAddr' => '127.0.0.1', 'PeerPort' => $port); printf("%s 3\n", $fh ? "ok" : "not ok"); eval { for (my $i = 0; $i < 20; $i++) { if (!$fh->print("$i\n") || !$fh->flush()) { die "Error while writing $i: " . $fh->error() . " ($!)"; } my $line = $fh->getline(); die "Error while reading $i: " . $fh->error() . " ($!)" unless defined($line); die "Result error: Expected " . ($i*2) . ", got $line" unless ($line =~ /(\d+)/ && $1 == $i*2); } };

Comment on Cannot read socket fh in Net::Daemon test
Download Code
Re: Cannot read socket fh in Net::Daemon test
by Anonymous Monk on Feb 16, 2011 at 23:07 UTC

      Corrected. Thanks for the reminder. The shown code in question is now downloadable, too.

      Some answers to this are on the bug ticket rt.cpan.org/Ticket/Display.html?id=65735, and have come from a combination of Daniel Macks and mcmahon. For one thing, threads on Windows have been supplanted by ithreads after Perl 5.10. In addition, a nice patch by Gaspar Chilingarov seems to have made a lot of headway today towards solving the problem.

      The t/thread.t tests are simply skipped if version >= 5.10. The only remaining problem is in telling the test harness/TAP - that it is okay not to have any tests for this. Just printing out "ok" to STDOUT or STDERR before exiting does not work. I will break out my old book - Perl Testing .. A Developer's Notebook - and figure this out.

      I should be able to get it from here, but if anyone could spare me the reading, that would be great.

        Got it. Just for completeness, I will list the last problem and its solution.

        I was getting the error below when tests were being skipped completely.

        Parse errors: No plan found in TAP output

        The solution was to use Test::More in t/thread.t, and add " plan(skip_all => $message); at the appropriate place, which was just before exiting the file, once it became known that all tests were to be skipped.

        Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://888580]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2014-08-28 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls