Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Socket timeouts without ALARM

by ton (Friar)
on Nov 09, 2001 at 07:12 UTC ( [id://124280]=perlquestion: print w/replies, xml ) Need Help??

ton has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how to set socket timeouts on a Win32 machine? I am using the raw sockets, not IO::Socket (long story), and I'd like to avoid using the ALARM signal if possible. I've tried using setsockopt in the C-like way, e.g.
setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, 1000);
This call will not flag strict, and it won't return an undef signifying an error, but it doesn't seem to alter the functionality of $socket. I tried the same call with 1 as the timeout value, and had the same lack of effect. Any ideas?

-Ton
-----
Be bloody, bold, and resolute; laugh to scorn
The power of man...

Replies are listed 'Best First'.
Re: Socket timeouts without ALARM
by dws (Chancellor) on Nov 09, 2001 at 08:11 UTC
    Does anyone know how to set socket timeouts on a Win32 machine?

    This questions comes up periodically (as yet another victim finds themself banging their head into the wall). One of the responses in LWP - timeout suggests that socket timeouts are only partially implemented on Win32.

    For further info, opinion, and conjecture, use Super Search to look for "socket timeout Win32" or "socket alarm win32". You'll get several hits that are worth looking at.

Re: Socket timeouts without ALARM
by mitd (Curate) on Nov 09, 2001 at 08:14 UTC
    This is a little out there but you aren't connecting your local socket to an outside socket through a IP Masquarading router by any chance?? this one has bitten moi before. You may be getting timed out at the router. I only know the exact fix on a Linux based router.

    Assuming 2.2 > kernel nad IPCHAIN:
    ipchains -M -S 86400 60 120 which set tcp tcpfin udp timeouts.

    Again this probably a long shot.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

ObPOE Plug
by Fletch (Bishop) on Nov 09, 2001 at 07:36 UTC

    POE is your friend when it comes to network programming. Trust POE.

    POE plugging aside, given that you're on Wintendo you're probably not going to find things behaving like they would on a real OS. And I seem to recall anectdotal stories about $SIG{ALARM} not playing nice on Wintendo as well.

Re: Socket timeouts without ALARM
by kschwab (Vicar) on Nov 09, 2001 at 07:26 UTC
    Set nonblocking mode and use select or just use IO::Socket, where the work is already done for you. Internally it's using nonblocking mode. The Timeout value is used for other operations, so you may want to reset it once the connection is up.
    my $socket=IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => 80, Proto => 'tcp', Timeout => 5);

      IO::Socket's timeouts mostly require alarm and so are just silently ignored under Win32.

              - tye (but my friends call me "Tye")
        Perhaps this was true at some point, but at least for ActiveState's perl, IO::Socket uses non-blocking mode in conjuction with IO::Select to implement the timeouts.

        Update: Well, this is true, the code is there, it uses non-blocking mode instead of alarm(), but it appears to be broken in Win32. <sigh>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-25 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found