Is Ruby Ready? IO method with get, puts, etc.

The Ruby standard library "io / wait" provides a method for IO objects ready?that returns non-nil if there is an input available, nil or false otherwise. I know that some methods, such as sysreadand syswrite, are unsafe for use with higher-level methods, such as getsand read, and wanted to know whether it was safe to ready?mix with higher-level methods. The ready-made method seems pretty useful and perhaps more elegant than relying on IO.select, but, surprisingly, I have not seen it use a lot. There is nothing in the documentation to indicate that it would be unsafe to use with readorgetsI just want to make sure that I don’t mix incompatible methods, which can ultimately lead to unexpected read / write socket behavior.

Change . I suppose I should mention that I am using Ruby 1.8.7.

+3
source share
1 answer

I don't have much experience with Ruby, but I have a lot of experience with libc, and I believe that yes, it is safe. The odds are pretty good, which is "done" implemented in terms of select () or poll () ...

"ready" select(), timeval tv_sec tv_usec, "ready" , ... -

+3

Source: https://habr.com/ru/post/1723602/


All Articles