Biker has asked for the wisdom of the Perl Monks concerning the following question:
I have an annoying socket related problem.
After a lot of trial and error I have found a work-around to the problem and my code is now functional.
On the other hand, I don't understand why my work-around works, neither why it is required. This is where your help and explanations will be much appreciated.
#!/usr/bin/perl -w require 5.005; use strict; use IO::Socket; for(1..100000) { open_sock(); } exit; sub open_sock { my $answer; my $sock=IO::Socket::INET->new(PeerAddr=>'10.118.32.31', PeerPort=>1955, Proto=>'tcp', Timeout=>20)|| die("Failed to open socket.\n"); # Writing to the socket makes no difference. #print $sock "x"; # Reading from the socket closes the memory leak. # Nothing gets printed on STDOUT from the print statement, # i.e. there was nothing to read. Right? while(defined($answer=<$sock>)) { print("Answer: $answer\n"); } close($sock); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Memory leak with socket
by Abigail-II (Bishop) on Aug 14, 2002 at 13:19 UTC | |
by Biker (Priest) on Aug 14, 2002 at 13:21 UTC | |
by Abigail-II (Bishop) on Aug 14, 2002 at 13:32 UTC | |
Re: Memory leak with socket
by dws (Chancellor) on Aug 14, 2002 at 17:33 UTC |