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

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; } #-----------------------

Replies are listed 'Best First'.
Re: perl.exe crash in win32 with use of fork and sockets
by tachyon (Chancellor) on Aug 05, 2001 at 00:10 UTC

    Perl on Win 98 does not support forking so you are forked so as to speak. Sorry to be the bearer of bad news.

    Update

    crazyinsomniac says the latest builds of winblows perl (for the last 6 months at least), all emulate fork on winblows (and that's why you can't rely on it).

    Ouch, out of date and wrong all in one sentence. /msg me Get with the program :-Þ

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Blah, my Win98 box forks (no, not in the "barfs" sense, but that too ;)) all the time... Wonder what's different.

        Hmm, crazyinsomniac and Amoe are right. I am wrong. You can fork on Windows these days, at least using AS Build 620 on Win95.

        C:\>type fork.pl #!/usr/bin/perl -w defined(my $pid = fork()) || die "Can't fork!"; print $pid ? "Parent\n" : "Child\n"; C:\>perl fork.pl Parent Child C:\>

        This is news to me. Thanks crazy and co this is forkin good to know.

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: perl.exe crash in win32 with use of fork and sockets
by Anonymous Monk on Aug 05, 2001 at 04:46 UTC
    Interesting, it doesn't quite crash on my machine. If you're using ActiveState - read up on perlfork - it's still in experimental stages. You may want to use the Thread library instead.