From: Brian Candler Date: 2008-11-14T06:20:07+09:00 Subject: Re: How to set socket option SO_RCVTIMEO Zakaria wrote: > How to set socket option SO_RCVTIMEO in Windows XP? > The C version use somekind struct. First, read the option: irb(main):001:0> require 'socket' => true irb(main):002:0> s = TCPServer.new(1234) => # irb(main):003:0> s.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO) => "\000\000\000\000\000\000\000\000" So if it's a struct timeval, that's a 32-bit tv_sec followed by a 32-bit tv_usec. Not clear about the byte order, though, since it's all zero here. So let's try native byte ordering, to set a timeout of 1.5 seconds (1 second + 500,000 microseconds): irb(main):008:0> n = [1, 500_000].pack("I_2") => "\001\000\000\000 \241\a\000" irb(main):009:0> s.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, n ) => 0 irb(main):010:0> s.accept Errno::EAGAIN: Resource temporarily unavailable from (irb):10:in `accept' from (irb):10 from :0 Yep, there was a pause of 1.5 seconds before the exception was raised. Look OK? -- Posted via http://www.ruby-forum.com/.