Click here to get back home

Net::Server - how to hook post_accept

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Net::Server - how to hook post_accept shutterstock 08-20-2006
Posted by shutterstock on August 20, 2006, 6:27 pm
Please log in for more thread options


Heya
I'm using Net::Server with the PreFork personality - and I'm trying to
hook post_accept. I would like have my proc called each time there is a
new connection.

What is the way to do this? The documentation doesn't provide it - and
I can't seem to find the answer online..

I tried to do a

sub post_accept {
<<do what i need each time i get a new cnx>>
}

but it seems to break the flow - and lock up the connection.. nothing
else gets handled (process_request never gets called, etc.) if I define
this sub. If I don't include the post_accept proc, my process_request
gets called just fine... How come I can hook process_request without
breaking the flow, but not post_accept?

How do I get the callback/hook whenever a new connection appears?

thanks!
Jon


Posted by Andy Hassall on August 20, 2006, 6:37 pm
Please log in for more thread options



>I'm using Net::Server with the PreFork personality - and I'm trying to
>hook post_accept. I would like have my proc called each time there is a
>new connection.
>
>What is the way to do this? The documentation doesn't provide it - and
>I can't seem to find the answer online..
>
>I tried to do a
>
>sub post_accept {
> <<do what i need each time i get a new cnx>>
>}
>
>but it seems to break the flow - and lock up the connection.. nothing
>else gets handled (process_request never gets called, etc.) if I define
>this sub. If I don't include the post_accept proc, my process_request
>gets called just fine... How come I can hook process_request without
>breaking the flow, but not post_accept?
>
>How do I get the callback/hook whenever a new connection appears?

Define a sub post_accept_hook, rather than overriding post_accept in your
subclass.

http://search.cpan.org/~rhandom/Net-Server-0.94/lib/Net/Server.pm
"
$self->post_accept_hook()

This hook occurs after a client has connected to the server. At this point
STDIN and STDOUT are mapped to the client socket. This hook occurs before the
processing of the request.
"

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Posted by shutterstock on August 20, 2006, 6:42 pm
Please log in for more thread options



> Define a sub post_accept_hook, rather than overriding post_accept in your
> subclass.
>
> http://search.cpan.org/~rhandom/Net-Server-0.94/lib/Net/Server.pm
> "
> $self->post_accept_hook()
>

For some reason - if i define post_accept_hook - it never gets called!
i just tried it again - and i can't seem to get that thing called.

How come the docs define

sub process_request {
}

and not process_request_hook?

there seems to be an inconsistency?
sub process_request { } works great - and its the same type of hook!

Jon


Posted by Andy Hassall on August 20, 2006, 6:59 pm
Please log in for more thread options



>> Define a sub post_accept_hook, rather than overriding post_accept in your
>> subclass.
>>
>> http://search.cpan.org/~rhandom/Net-Server-0.94/lib/Net/Server.pm
>> "
>> $self->post_accept_hook()
>
>For some reason - if i define post_accept_hook - it never gets called!
>i just tried it again - and i can't seem to get that thing called.
>
>How come the docs define
>
>sub process_request {
>}
>
>and not process_request_hook?
>
>there seems to be an inconsistency?
>sub process_request { } works great - and its the same type of hook!

They're not really the same type of hook. The *_hook subs are for doing
additional stuff after the server personality has handled that part of the
request cycle.

process_request is where you plug in your user code to do something useful
once the server has handled all the network stuff - so there isn't a
process_request_hook.

There does seem to be a call to $self->post_accept_hook in
run_client_connection in Net::Server, although I remember seeing a problem in
at least one version of Net::Server where one of the documented hook subs
wasn't called.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Posted by shutterstock on August 21, 2006, 1:15 pm
Please log in for more thread options


Ah - I got it.

works now. I guess i was just confused as to when to add the _hook to
the end of the sub.

Jon


Similar ThreadsPosted
Net::Server -> tftpd ? May 28, 2006, 6:21 am
TACACS+ with Cisco ACS server 3.2 August 6, 2004, 10:26 am
Start server for test ? May 16, 2005, 12:52 pm
Serialization by SOAP server July 7, 2006, 8:37 am
soaplite server and .net client September 14, 2006, 9:04 pm
Problems with Net::MySQL on OS X Server November 10, 2006, 7:01 pm
SQL Server triggers (dbi:ODBC vs dbi:Sybase) August 12, 2004, 9:15 am
XML-RPC server using Frontier::Daemon keeps crashing August 25, 2004, 12:06 pm
ForkOnAccept for SOAP::Lite TCP server November 27, 2004, 11:32 am
Using Net::Telnet to connect to Perl server January 22, 2005, 12:57 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap