Hi, I am trying to create a non-blocking client / server app, using INET sockets. I am on ActiveState Perl on Win32

I have read the entire (every page ;-) of Network Programming With Perl (great book, but I am still stuck)

My program leaks 4K chunks of something quite regularly (by looking at taskmanager.)

Anyone mind running these 2 programs and see if it also leaks for you? Of course if you spot the bug that would be GREAT !!!

All error checking has been removed for readability

CLIENT ------
use IO::Socket; use IO::Select; use Time::HiRes; use strict; for (1..500) { my $socket = IO::Socket::INET->new("localhost:12002") or die "no s +ocket"; print $socket "this is a test 123\n"; print $socket "this is a test 456\n"; Time::HiRes::sleep(.5); $socket->close() or die "error closing"; }
SERVER ------
use IO::Socket; use IO::Select; use Time::HiRes; use strict; my $listen_socket; my $readers; my %sessions; CreateListener(); while (1) { Poll(); print "."; Time::HiRes::sleep(.08); } sub CreateListener() { $listen_socket = IO::Socket::INET->new(LocalPort => 12002, Proto => 'tcp', Reuse => 1, Listen => 50); $listen_socket->blocking(0); $readers = IO::Select->new($listen_socket); $readers->add($listen_socket); } sub Poll { my @ready = $readers->can_read(0); return if (!@ready); my $handle = shift @ready; if ($handle) { if ($handle eq $listen_socket) { my $connect = $listen_socket->accept(); $sessions{"$connect"}{status} = 'first_connect'; $readers->add($connect); } else { my $user_input; my $bytes = sysread($handle, $user_input, 16384); if ($bytes && $bytes > 0) { chomp($user_input); if ($sessions{"$handle"}{status} eq "first_connect") { # Save data until socket is closed... $sessions{"$handle"}{status} = "next_connect"; $sessions{"$handle"}{data} = $user_input; } else { # Append data until socket is closed... $sessions{"$handle"}{data} .= $user_input; } } if (!$bytes) { # Got it all print $sessions{"$handle"}{data} . "\n"; # Close this socket $readers->remove($handle); delete $sessions{"$handle"}{status}; delete $sessions{"$handle"}{data}; close $handle; undef $handle; } } } }

In reply to nonblocking but leaking... by smackdab

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.