Net::Server - how to hook post_accept
Net::Server - how to hook post_accept
am 21.08.2006 00:27:38 von shutterstock
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 {
<>
}
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
Re: Net::Server - how to hook post_accept
am 21.08.2006 00:37:19 von Andy Hassall
On 20 Aug 2006 15:27:38 -0700, "shutterstock" wrote:
>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 {
> <>
>}
>
>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/Serv er.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
Re: Net::Server - how to hook post_accept
am 21.08.2006 00:42:06 von shutterstock
> 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/Serv er.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
Re: Net::Server - how to hook post_accept
am 21.08.2006 00:59:04 von Andy Hassall
On 20 Aug 2006 15:42:06 -0700, "shutterstock" wrote:
>> 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/Serv er.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
Re: Net::Server - how to hook post_accept
am 21.08.2006 19:15:19 von shutterstock
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