class Excon::Socket

Attributes

data[RW]
remote_ip[R]

Public Class Methods

new(data = {}) click to toggle source
# File lib/excon/socket.rb, line 24
def initialize(data = {})
  @data = data
  @nonblock = data[:nonblock]
  @read_buffer = String.new
  @eof = false
  connect
end

Public Instance Methods

legacy_readline() click to toggle source
# File lib/excon/socket.rb, line 59
def legacy_readline
  begin
    Timeout.timeout(@data[:read_timeout]) do
      @socket.readline
    end
  rescue Timeout::Error
    raise Excon::Errors::Timeout.new('read timeout reached')
  end
end
local_address() click to toggle source
# File lib/excon/socket.rb, line 77
def local_address
  unpacked_sockaddr[1]
end
local_port() click to toggle source
# File lib/excon/socket.rb, line 81
def local_port
  unpacked_sockaddr[0]
end
params() click to toggle source
# File lib/excon/socket.rb, line 10
def params
  Excon.display_warning('Excon::Socket#params is deprecated use Excon::Socket#data instead.')
  @data
end
params=(new_params) click to toggle source
# File lib/excon/socket.rb, line 15
def params=(new_params)
  Excon.display_warning('Excon::Socket#params= is deprecated use Excon::Socket#data= instead.')
  @data = new_params
end
read(max_length = nil) click to toggle source
# File lib/excon/socket.rb, line 32
def read(max_length = nil)
  if @eof
    return max_length ? nil : ''
  elsif @nonblock
    read_nonblock(max_length)
  else
    read_block(max_length)
  end
end
readline() click to toggle source
# File lib/excon/socket.rb, line 42
def readline
  return legacy_readline if RUBY_VERSION.to_f <= 1.8_7
  buffer = String.new
  begin
    buffer << @socket.read_nonblock(1) while buffer[-1] != "\n"
    buffer
  rescue Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable
    select_with_timeout(@socket, :read) && retry
  rescue OpenSSL::SSL::SSLError => error
    if error.message == 'read would block'
      select_with_timeout(@socket, :read) && retry
    else
      raise(error)
    end
  end
end
write(data) click to toggle source
# File lib/excon/socket.rb, line 69
def write(data)
  if @nonblock
    write_nonblock(data)
  else
    write_block(data)
  end
end