BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

If i run this script and connect to 127.0.0.1 in my browser(s) it serves me the embedded form and accepts and displays the posted data from submitting that form:

#! perl -slw use strict; #use threads; use IO::Socket; $|++; my $page = do{ local $/; <DATA> }; my $s = IO::Socket::INET->new( Listen => 1, LocalPort => 80 ); while( my $c = $s->accept ) { printf "Connection accepted from %s\n", $c->peerhost; # async { my $req = <$c>; printf "Request received: %s\n", $req; my( $act, $url, $mode ) = split ' ', $req; if( $act eq 'GET' ) { if( $url eq '/' ) { print $c $page; } else { print $c '404 Not found'; } } elsif( $act eq 'POST' ) { my $read = 0; print $c '200 OK'; print $c ''; print $req; while( defined( $_ = <$c> ) and length() !=2 ) { printf "%s", $_; $read = $1 if $_ =~ m[Content-Length: (\d+)]; } print "\n", '=' x 20; my $post; read( $c, $post, $read ); print $post; } else { print $c '404 Not found'; } print $c ''; shutdown( $c, 2 ); close $c; # }->detach; } __DATA__ HTTP/1.0 200 OK Date: Mon, 28 Feb 2012 22:38:34 GMT Server: Perl/IOSocket/BrowserUk Content-Length: 3057 Connection: close Content-Type: text/html; charset=iso-8859-1 <html> <head> <title>A test</title> </head> <body> <h4>A test</h4> <p>A test paragraph. <form method=post> select: <select name=select><option value="2">2</option><option value= +"3">2</option><option value="4">4</option><option value="5">5</option +><option value="6">6</option><option value="7">7</option></select> <br />Radio: <input type="radio" name="radio" value="yes" /> Yes <inpu +t type="radio" name="radio" value="no" /> No <br />Radio2: <input type="radio" name="radio2" value="yes" />Yes<inpu +t type="radio" name="radio2" value="no" />No. <br />Select2: <select name=select2><option value="1">1</option><optio +n value="2">2</option><option value="3">3<option><option value="4">4< +/option><option value="5">5</option><option value="6">6</option><opti +on value="7">7</option><option value="8">8</option><option value="9"> +9</option><option value="10">10</option></select> <table border="1"> <tr><th>________</th><th>A</th><th>B</th><th>C</th></tr> <tr> <td>A</td> <td>-</td> <td> <select name="1.2"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td> <select name="1.3"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> </tr> <tr> <td>B</td> <td> <select name="2.1"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td>-</td> <td> <select name="2.3"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> </tr> <tr> <td>C</td> <td> <select name="3.1"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td> <select name="3.2"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td>-</td> </tr> </table> <input type="submit" value="Submit" /> </form> </body> </html>

(Note: this is drastically cut down toward the minimum, (the re-boot and trim cycle is tedious), that displays the following problem.)

However, if I connect to it via my external IP address -- port 80 forwarded to this machine via NAT -- the connect is accepted (at the server end), the browser spins its wheels for a few seconds and then the machine bluescreens! (The only non-hardware related bluescreen I've ever had with this OS.)

This happens regardless of the browser I use -- hence I exclude that.

A 'proper' httpd runs fine on this setup, hence I exclude the tcpip stack, OS etc.

Which brings me back to Perl and my own code. I've disabled the threading to exclude that red-herring from the picture. So that leaves something wrong in my handling of HTTP -- then why would it run fine locally? -- and IO::Socket -- ditto!

So, having excluded everything I can think of, and still having the problem, I throw it open to see what idiocies I am committing?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re: [OT]ish: HTTP/HTML/IO::Socket sanity check. (packets)
by tye (Sage) on Feb 28, 2012 at 07:07 UTC

    I'd run wireshark and compare the localhost cases with this script vs. with a "proper httpd". I suspect the proper httpd may send a very few relatively large packets while your Perl script may send a lot of tiny packets.

    This seems likely to be a bug in your network driver. I have no guesses what precisely about the (presumed, possible) tiny packets (or just different packets) would make your driver so unhappy.

    You might want to have another computer run a promiscuous wireshark / tcpdump so you can see the packets coming in and that make it out in the bluescreen case as well.

    - tye        

Re: [OT]ish: HTTP/HTML/IO::Socket sanity check.
by Anonymous Monk on Feb 28, 2012 at 04:31 UTC

    So, having excluded everything I can think of, and still having the problem, I throw it open to see what idiocies I am commiting?

    Well, each BSOD comes with an error message, so you're not relaying that

    Remember this? What perl are you running? IO::Socket? OS? msvcrt?

    Also , run the debugger already, you know you have to :)

     perl -le" undef $ENV{SYSTEMROOT}; exec qw(perl.exe -e die); "

      Well, each BSOD comes with an error message, so you're not relaying that

      Okay, what can you make of this, the only variant info from the BSOD screen;

      STOP: 0x0000007E (0XFFFFFFFFC0000005, 0XFFFFF80003667F61, 0XFFFFFA6001 +B08978, 0XFFFFFA6001B08350 )
      Remember this?

      If it was a segfault, I could supply that type of info, but it is never displayed because the BSOD takes priority. Nothing is logged in either the system or application logs. It doesn't get chance.

      What perl are you running? IO::Socket? OS? msvcrt?

      Versions of stuff:

      C:\test>perl -v This is perl, v5.10.1 built for MSWin32-x64-multi-thread (with 2 registered patches, see perl -V for more detail) Copyright 1987-2009, Larry Wall Binary build 1007 [291969] provided by ActiveState http://www.ActiveSt +ate.com Built Jan 27 2010 14:12:21 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. C:\test>perl -MIO::Socket -E"say $IO::Socket::VERSION" 1.31 C:\test>ver Microsoft Windows [Version 6.0.6001] C:\test>dumpbin /headers \Windows\system32\msvcrt.dll Microsoft (R) COFF/PE Dumper Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file \Windows\system32\msvcrt.dll PE signature found File Type: DLL FILE HEADER VALUES 8664 machine (x64) 6 number of sections 4791AD6B time date stamp Sat Jan 19 07:57:31 2008 0 file pointer to symbol table 0 number of symbols F0 size of optional header 2022 characteristics Executable Application can handle large (>2GB) addresses DLL
      Also , run the debugger already, you know you have to :)

      I'm not sure how running "the debugger" (Perl or other) will help since all useful information will be obliterated by the BSOD?

       perl -le" undef $ENV{SYSTEMROOT}; exec qw(perl.exe -e die); "

      I have quiet literally no idea what that is meant to be telling me (to do?)?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        Okay, what can you make of this, the only variant info from the BSOD screen;

        Perhaps http://zapp5.staticworld.net/howto/graphics/215201-0110-bsod_original.jpg will help you see other useful information on your bluescreen.

        I'm not sure how running "the debugger" (Perl or other) will help since all useful information will be obliterated by the BSOD?

        If you use the debugger to single-step through your script, then I presume that you'll be able to narrow down the source of the problem to a single Perl statement, unless the bluescreen also obliterates your own memories. (Or it may only tell you that the bluescreen doesn't happen when your script is run with the debugger enabled, of course.)

        Meanwhile, I'll see if I can spot anything suspicious in the code, which I haven't had a chance to study yet.

        - tye