Skip to content

Instantly share code, notes, and snippets.

@siassaj
Created December 6, 2014 09:42
Show Gist options
  • Save siassaj/f28b61f27e810ecf538e to your computer and use it in GitHub Desktop.
Save siassaj/f28b61f27e810ecf538e to your computer and use it in GitHub Desktop.
huge_string.size
=> 65550
data.size
=> 65536
data.include? "ends in awesome"
=> false
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