Skip to content

Instantly share code, notes, and snippets.

@jstorimer
Last active December 21, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstorimer/6337721 to your computer and use it in GitHub Desktop.
Save jstorimer/6337721 to your computer and use it in GitHub Desktop.
require 'socket'
client = TCPSocket.new('localhost', 4481)
payload = "Lorem ipsum" * 100_000
total_bytes_written = 0
remaining_payload = payload
begin
puts 'looping'
IO.select(nil, [client]) # wait until the client is ready (this prevents EAGAIN)
bytes = client.write_nonblock(remaining_payload) # write as much as we can
rest_of_payload = payload[bytes..-1] # slice off the rest of the payload
total_bytes_written += bytes # maintain the count of total bytes written so far
end while total_bytes_written < payload.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment