class HTTPClient::JavaSocketWrap
Constants
- BUF_SIZE
Public Class Methods
connect(socket, site, opts = {})
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 23 def self.connect(socket, site, opts = {}) socket_addr = InetSocketAddress.new(site.host, site.port) if opts[:connect_timeout] socket.connect(socket_addr, opts[:connect_timeout]) else socket.connect(socket_addr) end socket.setSoTimeout(opts[:so_timeout]) if opts[:so_timeout] socket.setKeepAlive(true) if opts[:tcp_keepalive] socket end
new(socket, debug_dev = nil)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 35 def initialize(socket, debug_dev = nil) @socket = socket @debug_dev = debug_dev @outstr = @socket.getOutputStream @instr = BufferedInputStream.new(@socket.getInputStream) @buf = (' ' * BUF_SIZE).to_java_bytes @bufstr = '' end
Public Instance Methods
<<(str)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 98 def <<(str) rv = @outstr.write(str.to_java_bytes) debug(str) rv end
close()
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 44 def close @socket.close end
closed?()
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 48 def closed? @socket.isClosed end
eof?()
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 52 def eof? @socket.isClosed end
flush()
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 104 def flush @socket.flush end
gets(rs)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 56 def gets(rs) while (size = @bufstr.index(rs)).nil? if fill() == -1 size = @bufstr.size break end end str = @bufstr.slice!(0, size + rs.size) debug(str) str end
read(size, buf = nil)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 68 def read(size, buf = nil) while @bufstr.size < size if fill() == -1 break end end str = @bufstr.slice!(0, size) debug(str) if buf buf.replace(str) else str end end
readpartial(size, buf = nil)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 83 def readpartial(size, buf = nil) while @bufstr.size == 0 if fill() == -1 raise EOFError.new('end of file reached') end end str = @bufstr.slice!(0, size) debug(str) if buf buf.replace(str) else str end end
sync()
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 108 def sync true end
sync=(sync)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 112 def sync=(sync) unless sync raise "sync = false is not supported. This option was introduced for backward compatibility just in case." end end
Private Instance Methods
debug(str)
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 132 def debug(str) @debug_dev << str if @debug_dev && str end
fill()
click to toggle source
# File lib/httpclient/jruby_ssl_socket.rb, line 120 def fill begin size = @instr.read(@buf) if size > 0 @bufstr << String.from_java_bytes(@buf, Encoding::BINARY)[0, size] end size rescue java.io.IOException => e raise OpenSSL::SSL::SSLError.new("#{e.class}: #{e.getMessage}") end end