This is almost too embarrasing to ask help about, but no matter how many times I go over perlfaq5, it's not sinking in. I'm fiddling with the examples in the Stein Network Programming with Perl book, and managed to set up a workin tcp server. Just for giggles, I wanted to break out the authentication routine to it could be overridden by other modules.

Just for a little background, the tcp conversation consist of an authorization request, an auth. response, then it loops to service request after request. Each request and response is fixed in length.

Here's the inner loop of the server module (gutted for shortness):

sub start { while (1) { next unless $session = $self->__socket->accept; my $quit = 0; my $auth; read($session, $auth, 50); ... #do auth stuffs ... while (! $quit) { my $request; read($session, $request, 150); if ($request =~ /^Q\s*$/i) { $quit = 1; } else { print $session 'foo response'; }; }; close($session); next; }; ... }

Everything works as expected. Now I would like to pass the $session (IO::Socket::INET glob) to an anthentication sub. I've tried every encantation of passing globs, globrefs, and localizing, but regardless, my $session in the authenticate sub is empty.

sub authenticate { my ($self, $session) = @_; # $session is undef. return 1; } sub start { while (1) { next unless $session = $self->__socket->accept; my $quit = 0; if (!authenticate($session)) { $session->shutdown; next; } ... while (! $quit) { my $request; read($session, $request, 150); if ($request =~ /^Q\s+/i) { $quit = 1; } else { print $session 'foo response'; }; }; close($session); next; }; ... }

Obviously, I don't truely understand what $session really is, nr how to properly pass it. Feel free to institute broad usage of a moderate sized clue-stick upon the poster.

Thanks,
-=Chris


In reply to Passing IO::Socket::INET by jk2addict

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.