Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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?

Replies are listed 'Best First'.
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.


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?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-08-19 20:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found