Created
December 6, 2014 09:42
-
-
Save siassaj/f28b61f27e810ecf538e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
huge_string.size | |
=> 65550 | |
data.size | |
=> 65536 | |
data.include? "ends in awesome" | |
=> false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
huge_string = "B" * 0xFFFF | |
huge_string << "ends in awesome" | |
data = "" | |
Thread.new { sleep 5; data = io_out.read_all } | |
io_in.puts huge_string | |
################################################# | |
# for io_out; read_all is: | |
def has_data?(timeout = 0) | |
IO.select([self], nil, nil, timeout) ? true : false | |
end | |
def read_all opts = {} | |
opts[:nonblocking] ||= false | |
return nil if opts[:nonblocking] && !has_data? | |
# Block until data has arrived. | |
data = readpartial 0xFFFF | |
# If there is more data in the buffer, retrieve it nonblocking. | |
data += readpartial 0xFFFF while has_data? | |
data | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment