Skip to content

Instantly share code, notes, and snippets.

@jstorimer

jstorimer/gist:6337721

Last active Dec 21, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.