Skip to content

Instantly share code, notes, and snippets.



Last active Dec 21, 2015
What would you like to do?
require 'socket'
client ='localhost', 4481)
payload = "Lorem ipsum" * 100_000
total_bytes_written = 0
remaining_payload = payload
puts 'looping', [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