×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Perl Socket Crash: Illegal Operation on Perl56.dll with FORK & SOCKET

Perl Socket Crash: Illegal Operation on Perl56.dll with FORK & SOCKET

Perl Socket Crash: Illegal Operation on Perl56.dll with FORK & SOCKET

(OP)
Hello.

I just downloaded the latest version of Perl (ActivePerl-5.6.0.613.msi) for Windows 98. I was very pleased that there is the command FORK for windows users.

I made use of the socket command and fork and found a serious problem with it. My program acts like a proxy, an middle-man server between my IE5 browser and the actual Internet remote connection. I make a request from IE5, the request gets picked up by my Proxy server, the server makes a separate remote call for the desired site, and returns the data back to the original IE5 call; it FORKs for mutliple calls. Now when I go to use this program, about 10 seconds into it (i don't see anything returned in IE5 though) the perl script crashes popping up a Windows 98 "Illegal Operations" window. Below is the full text reported in DETAILS:
-----
PERL caused an invalid page fault in
module PERL56.DLL at 015f:2806faad.
Registers:
EAX=d9a0dabc CS=015f EIP=2806faad EFLGS=00010a86
EBX=2f62696c SS=0167 ESP=1801fe48 EBP=1801fe54
ECX=00000001 DS=0167 ESI=08fbf064 FS=56bf
EDX=9ed6decc ES=0167 EDI=09034244 GS=6896
Bytes at CS:EIP:
8b 5c 02 fc 8d 34 02 84 d9 75 1e 8b 4d fc 57 39
Stack dump:
08fbf064 08b7196c 08664db0 1801fea4 280709f1 00000001 2806c050 08663024 09034428 2804b80b 09034428 08b7196c 08fbf064 09034244 09034244 00000000
---

I have also attached my proxy server called to this message (below). Simply run it from the DOS command line with: "Perl Proxy.Pl". It will sit there waiting for a call. Now go to your webbrowser and set the proxy server to: localhost (127.0.0.1 port 80). Now type in any remote URL to connect to (ie. http://www.yahoo.com). My proxy server will pick up the call and try to make the remote URL call. After about 10 seconds or less the Illegal Operations window (PerlCrash.GIF) will pop up. Maybe it has to do with the new FORK command or perhaps the error has to do with line 39 in my PROXY.PL script which reads:

$remote1 = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"$serv", PeerPort=>"80", Reuse=>1) or goto AX; binmode($remote1);

This is the line which connects out to the remote URL that the browser is trying to view. Maybe because the browser has to hit the URL multiple times (graphic files + html) fillng up the cue and generating multli calls to line 39 above.

Well, I hope i've provided enough details. Please let me know what I can do to resolve this problem. I'd very much appreciate that.

Again, thank you.

j.

---PROXY.PL---
use IO::Socket;

$SIG{CHLD} = sub {wait ()};

$main_sock = new IO::Socket::INET (LocalHost=>'localhost',LocalPort=>80,Listen=>100,Proto=>'tcp',Reuse=>1,); die "Socket could not be created. Reason: $!\n" unless ($main_sock);

while ($new_sock = $main_sock->accept())
{
$pid = fork(); die "Cannot fork: $!" unless defined($pid);

if ($pid == 0) #Handle forked
{
# Child process
if (defined ($buff = <$new_sock>))
{
# do something with $buff ....
@header = split(' ', $buff);
$method=$header[0]; $url = $header[1]; $httpver=$header[2];
@url=split(/\?--/,$url); $url[0]=~s/http:\/\///g; $url[1]=~s/http:\/\///g;
$url[0]=~/^([^\/]*)(\/[^\{]*)/; $serv=$1; $doc=$2; $url[1]="http://$url[1]" if ($url[1]);

$headext=""; $d=0; $ccl=0;
while($l=<$new_sock>)
{
if ($l=~/Referer: ([^\{]*)/i && $url[1]) {$headext.="Referer: $url[1]\r\n";$d=1; next;}
elsif ($l=~/^\r\n/ && !$d && $url[1])
{$headext.="Referer: $url[1]\r\n";$d=1;}
elsif ($l=~/Content-length: ([0-9]*)/i)
{$ccl=$1;}
$l=~s/\r¦\n//g;
$headext.="$l\r\n";
last if ($l eq "");
}
if ($ccl){read($buff,$data,$ccl);$headext.=$data;}

print "\n\n<Connecting to: http://$serv$doc>\n";
print "$method $doc $httpver\n$headext";

$remote1 = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"$serv", PeerPort=>"80", Reuse=>1) or goto AX; binmode($remote1); #die "Can't connect to \"$serv\" $!\n";

goto AX if (!&ChkSock($remote1));
print $remote1 "$method $doc $httpver\r\n$headext";
$cl=0; $data="";
while ($l=<$remote1>)
{
print $new_sock "$l";
if ($l=~/content-length: ([0-9]*)/i)
{$cl=$1;}
last if ($l=~/^\r\n/ && $cl);
last if (!&ChkSock($remote1));
goto AX if (!&ChkSock($new_sock));
}
if ($cl){read($remote1,$data,$cl);print $new_sock "$data";}
AX: close $remote1;
}
exit(0); # Child process exits when it is done.
} # else 'tis the parent process, which goes back to accept()
}
close ($main_sock);

sub ChkSock
{
$socks=$_[0];
if (!defined($socks))
{print "\n**CANCELLED**\n";return 0;}
return 1;
}
---

RE: Perl Socket Crash: Illegal Operation on Perl56.dll with FORK & SOCKET

two thoughts (three actually)

1 - try a small script that does nothing but fork and..., to test the operation of the fork() function.

2 - www.perl.com says that 5.005_03 is the current stable version Active State say that their *previous* version of ActivePerl v5.22 is based upon 5.005. Might be worth having a look at that, it is mentioned on:

http://www.activestate.com/ActivePerl/faq.htm

3 - Cool program <smile>

Keep us informed.

Mike

Mike Lacey
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close