Last active
December 21, 2015 16:59
-
-
Save jstorimer/6337721 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
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