Created
September 16, 2009 15:16
-
-
Save toto/188098 to your computer and use it in GitHub Desktop.
Net/HTTP has some serious bugs regarding timeout in JRuby. Therefor it is useful to just use the Java classes to get a reliable timeout
This file contains hidden or 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 'java' | |
import java.net | |
import java.io | |
uri = java.net.URL.new("http://127.0.0.1") | |
con = uri.openConnection() | |
con.setConnectTimeout(1000) # in millisecs so this is 1 sec | |
con.setReadTimeout(1000) | |
in_reader = java.io.BufferedReader.new(java.io.InputStreamReader.new(con.getInputStream())); | |
buf = '' | |
while inputLine = in_reader.readLine do | |
buf << inputLine; | |
end | |
in_reader.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment