Skip to content

Instantly share code, notes, and snippets.

@bararchy
Last active August 29, 2015 14:18
Show Gist options
  • Save bararchy/5821d4227c95cb865872 to your computer and use it in GitHub Desktop.
Save bararchy/5821d4227c95cb865872 to your computer and use it in GitHub Desktop.
def self.read_for_tcp_proxy(socket)
data = socket.read_nonblock(16_384)
while socket.pending > 0
data += socket.read_nonblock(16_384)
end
data
rescue IO::WaitReadable
IO.select([socket])
retry
rescue IO::WaitWritable
IO.select(nil, [socket])
retry
rescue EOFError => e
return e
rescue OpenSSL::SSL::SSLError => e
if defined? data
return data
else
return e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment