Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

IO::Sockets timeout implementation confusion

by Sol-Invictus (Scribe)
on Jan 31, 2004 at 01:58 UTC ( #325485=perlquestion: print w/ replies, xml ) Need Help??
Sol-Invictus has asked for the wisdom of the Perl Monks concerning the following question:

On a tcp server socket, I want to use a timeout to log out clients that have become inactive after 5 mins, so after reading this:

(from IO::Socket pod)

timeout([VAL]) Set or get the timeout value associated with this socket. I +f called without any arguments then the current setting is returned. + If called with an argument the current setting is changed and +the pre- vious value returned.

I wrote a socket which opens like this:

use IO::Socket; use IO::Select; $max_msglen = 1024; $max_clients = 10; $port = 9999; $timeout = 300; $serverSocket = IO::Socket::INET->new( Proto=>"tcp", LocalPort=>$port, Listen=>$max_clients, Timeout =>$timeout, Reuse=>1 ); $sel = IO::Select->new($serverSocket);

but it doesn't time out the clients. Looking for answers I went here:

(from IO::Select pod)

select ( READ, WRITE, ERROR [, TIMEOUT ] ) "select" is a static method, that is you call it with the p +ackage name like "new". "READ", "WRITE" and "ERROR" are either "un +def" or "IO::Select" objects. "TIMEOUT" is optional and has the sam +e effect as for the core select call.

So now I'm really confused -

Firstly: What is the socket timeout I've set up actually doing?

Secondly: is the "core select" mentioned the same as the one I've tried to call on the socket at startup time?

Thirdly: Should I be checking for return values to catch the timeout event, if so where?

Comment on IO::Sockets timeout implementation confusion
Select or Download Code
Re: IO::Sockets timeout implementation confusion
by jdtoronto (Prior) on Jan 31, 2004 at 03:24 UTC
    The socket timeout is used within the connect() and accept() methods. It does not currently affect calls that send or receive data.

    One side effect of using the timeout is that the connect() and accept() calls are then interuptable, allowing a signal handler to gracefully interupt a process that is hung waiting for a connect() or accept() to complete. So in essence the timeout value tells the module how long we are prepared to block IO while awaiting a connect() or accpet(). You need to do the management of 'lost clients' at the SESSION level.

    jdtoronto

Re: IO::Sockets timeout implementation confusion
by Sol-Invictus (Scribe) on Jan 31, 2004 at 23:59 UTC
    ahh I forgot to add this is on a multiplexing socket.

    By session do you mean each pass through $select->handles ?

    Also as we're talking about blocking, obviously a multiplexing socket doesn't block, so do I have to set my own timers or can I use select ( READ, WRITE, ERROR [, TIMEOUT ] )?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://325485]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-09-19 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (144 votes), past polls