|
Revision 244, 1.2 kB
(checked in by nahi, 1 year ago)
|
|
| Line | |
|---|
| 1 |
require 'benchmark' |
|---|
| 2 |
require 'uri' |
|---|
| 3 |
require 'fileutils' |
|---|
| 4 |
|
|---|
| 5 |
def try_require(target) |
|---|
| 6 |
begin |
|---|
| 7 |
require target |
|---|
| 8 |
rescue LoadError |
|---|
| 9 |
warn("#{target} not loaded") |
|---|
| 10 |
end |
|---|
| 11 |
end |
|---|
| 12 |
|
|---|
| 13 |
try_require 'httpclient' |
|---|
| 14 |
require 'net/http' |
|---|
| 15 |
|
|---|
| 16 |
# following Net code block is not copirighed by me. |
|---|
| 17 |
# see: http://7fff.com/2008/12/20/faster-nethttp-for-ruby-186 |
|---|
| 18 |
module Net |
|---|
| 19 |
class BufferedIO |
|---|
| 20 |
alias rbuf_fill_replaced_by_bm rbuf_fill |
|---|
| 21 |
BUFSIZE = 1024 * 16 |
|---|
| 22 |
def rbuf_fill |
|---|
| 23 |
# HTTPS can't use the non-blocking strategy below in 1.8.6; so at least |
|---|
| 24 |
# increase buffer size over 1.8.6 default of 1024 |
|---|
| 25 |
if !@io.respond_to? :read_nonblock |
|---|
| 26 |
timeout(@read_timeout) { |
|---|
| 27 |
@rbuf << @io.sysread(BUFSIZE) |
|---|
| 28 |
} |
|---|
| 29 |
return |
|---|
| 30 |
end |
|---|
| 31 |
# non-blocking |
|---|
| 32 |
begin |
|---|
| 33 |
@rbuf << @io.read_nonblock(BUFSIZE) |
|---|
| 34 |
rescue Errno::EWOULDBLOCK |
|---|
| 35 |
if IO.select([@io], nil, nil, @read_timeout) |
|---|
| 36 |
@rbuf << @io.read_nonblock(BUFSIZE) |
|---|
| 37 |
else |
|---|
| 38 |
raise Timeout::TimeoutError |
|---|
| 39 |
end |
|---|
| 40 |
end |
|---|
| 41 |
end |
|---|
| 42 |
end |
|---|
| 43 |
end |
|---|
| 44 |
|
|---|
| 45 |
require 'open-uri' |
|---|
| 46 |
try_require 'rfuzz/session' |
|---|
| 47 |
try_require 'eventmachine' |
|---|
| 48 |
try_require 'curb' |
|---|
| 49 |
try_require 'httparty' |
|---|