jk2addict has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing IO::Socket::INET
by dws (Chancellor) on Jan 27, 2003 at 19:11 UTC | |
by jk2addict (Chaplain) on Jan 27, 2003 at 19:19 UTC | |
|
Re: Passing IO::Socket::INET
by l2kashe (Deacon) on Jan 27, 2003 at 19:19 UTC | |
|
Re: Passing IO::Socket::INET
by pfaut (Priest) on Jan 27, 2003 at 19:19 UTC |