I get the following error when I try to use the method "read_nonblock" from the "socket" library
IO::EAGAINWaitReadable: Resource temporarily unavailable - read would block
But when I try it through the IRB on the terminal it works fine
How can I make it read the buffer?
It is expected behaviour, when the data isn't ready in the buffer. Since the exception
IO::EAGAINWaitReadable
is originated from ruby version2.1.0
, in older version you must trapIO::WaitReadable
with additional port selection and retry. So do as it was adviced in the ruby documentation:For newer version os ruby you should trap
IO::EAGAINWaitReadable
also, but just with retrial reading for a timeout or infinitely. I haven't find out the example in the docs, but remember that it was without port selection:However some my investigations lead to that it is also better to do port selection on
IO::EAGAINWaitReadable
, so you'll can get:To support the code woth both versions of exception, just declare the definition of
IO::EAGAINWaitReadable
in lib/ core underif
clause: