Module: Aerospike::Socket::Base

Included in:
SSL, TCP
Defined in:
lib/aerospike/socket/base.rb

Instance Method Summary collapse

Instance Method Details

#closeObject



80
81
82
83
# File 'lib/aerospike/socket/base.rb', line 80

def close
  return if closed?
  super()
end

#connected?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/aerospike/socket/base.rb', line 76

def connected?
  !closed?
end

#initialize(*args) ⇒ Object



23
24
25
26
# File 'lib/aerospike/socket/base.rb', line 23

def initialize(*args)
  super(*args)
  @timeout = nil
end

#read(buffer, length) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/aerospike/socket/base.rb', line 28

def read(buffer, length)
  bytes_read = 0
  until bytes_read >= length
    result = read_from_socket(length - bytes_read)
    buffer.write_binary(result, bytes_read)
    bytes_read += result.bytesize
  end
end

#read_from_socket(length) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aerospike/socket/base.rb', line 37

def read_from_socket(length)
  begin
    read_nonblock(length)
  rescue ::IO::WaitReadable => e
    if ::IO::select([self], nil, nil, @timeout)
      retry
    else
      raise ::Aerospike::Exceptions::Connection.new("#{e}")
    end
  rescue => e
    raise ::Aerospike::Exceptions::Connection.new("#{e}")
  end
end

#timeout=(timeout) ⇒ Object



72
73
74
# File 'lib/aerospike/socket/base.rb', line 72

def timeout=(timeout)
  @timeout = timeout && timeout > 0 ? timeout : nil
end

#write(buffer, length) ⇒ Object



51
52
53
54
55
56
# File 'lib/aerospike/socket/base.rb', line 51

def write(buffer, length)
  bytes_written = 0
  until bytes_written >= length
    bytes_written += write_to_socket(buffer.read(bytes_written, length - bytes_written))
  end
end

#write_to_socket(data) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/aerospike/socket/base.rb', line 58

def write_to_socket(data)
  begin
    write_nonblock(data)
  rescue ::IO::WaitWritable => e
    if ::IO::select(nil, [self], nil, @timeout)
      retry
    else
      raise ::Aerospike::Exceptions::Connection.new("#{e}")
    end
  rescue => e
    raise ::Aerospike::Exceptions::Connection.new("#{e}")
  end
end