Hi Monks!
I'm trying to run this code in a Win98 box (using ActivePerl v5.6.1 build 626).
It *would* be something like a proxy server. I'm using LWP to fetch the objects for debug reasons, but the final code will connect to hosts via a normal socket.
What's the problem with the code? It crashes PERL.EXE (yes, the "this program executed an illegal operation....") when the second or third connection comes...
I've tried on a NT box without success..
The code:
#------------------------------------------------- #! perl use IO::Socket; use LWP::Simple; $listen_socket = IO::Socket::INET->new(LocalPort => 8080, Listen => 10, Proto => 'tcp', Reuse => 1); die unless $listen_socket; warn "Servidor iniciado. Aguardando conexoes... \n\n"; while (my $connection = $listen_socket->accept) { die unless defined ($child = fork()); if ($child == 0) { obtem_request($connection); $connection->close(); exit; } else { warn "Conexao recebida...\n"; $connection->close(); } } sub obtem_request { my $socket = shift; my $temp, $header; while ($status = read ($socket, $temp, 1)) { $header .= $temp; if ($header =~ /\r\n\r\n/ or $header =~ /\n\n/) { print $header; last; } } $header =~ /GET (.*?) HTTP\/1\.0/s; $page = get($1); print "Fetching $get\n\n"; print $socket 'Content-Type: text/html; charset=ISO-8859-1'."\r\n\ +r\n"; print $socket $page; } #-----------------------

In reply to perl.exe crash in win32 with use of fork and sockets by unb0rn

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.