0

Ruby 2.5's doc says that for:
myTCPServer = Socket.tcp(host, port, nil, nil, :connect_timeout=60),
the only option it accepts is :connect_timeout.

(Ruby 2.0's doc may have a copy-paste error, claiming that :timeout is another option, but not saying what that option does. At any rate, that option doesn't work in 2.5.1p57 on Ubuntu 18.04 LTS.)

Is the gem tcp_timeout the best way to make a TCP socket whose connected session can timeout on read for a specified duration, e.g via mySession.gets?
(Not a timeout on connect. Not a timeout on write.)

Or IO::select?

Camille Goudeseune
  • 2,934
  • 2
  • 35
  • 56
  • "The best way"? Who knows. There does not appear to be a built-in way. tcp_timeout uses IO::select under the hood, so that approach definitely works. A simple thread-based timer might also work. – Max Sep 11 '19 at 21:01

1 Answers1

0

Yes, IO::select, using recvfrom instead of gets (which might wait a while for a newline).

Camille Goudeseune
  • 2,934
  • 2
  • 35
  • 56