Class: Tarantool16::Connection::Dumb

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/tarantool16/connection/dumb.rb

Constant Summary

Constants included from Common

Common::CLOCK_KIND, Common::DEFAULT_RECONNECT, Common::REQ_EMPTY

Instance Attribute Summary

Attributes included from Common

#host

Instance Method Summary collapse

Methods included from Common

#_call, #_delete, #_init_common, #_insert, #_ping, #_replace, #_select, #_update, #format_authenticate, #format_request, #host_port, #next_sync, #now_f, #parse_greeting, #parse_response, #parse_size

Constructor Details

#initialize(host, opts = {}) ⇒ Dumb

Returns a new instance of Dumb.



8
9
10
11
12
13
14
# File 'lib/tarantool16/connection/dumb.rb', line 8

def initialize(host, opts = {})
  _init_common(host, opts)
  @nbuf = "\x00".b * 5
  @reconnect_time = now_f - 1
  @socket = nil
  _connect
end

Instance Method Details

#closeObject



42
43
44
45
46
47
48
49
# File 'lib/tarantool16/connection/dumb.rb', line 42

def close
  @reconnect = false
  if @socket
    @socket.close rescue nil
    @socket = false
    @s = 0
  end
end

#connected?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/tarantool16/connection/dumb.rb', line 51

def connected?
  @socket
end

#could_be_connected?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/tarantool16/connection/dumb.rb', line 55

def could_be_connected?
  @socket || (@socket.nil? && (@reconnect || @reconnect_time < now_f))
end

#disconnectObject



34
35
36
37
38
39
40
# File 'lib/tarantool16/connection/dumb.rb', line 34

def disconnect
  if @socket
    @socket.close rescue nil
    @socket = nil
    @s = 0
  end
end

#send_request(code, body, cb) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tarantool16/connection/dumb.rb', line 16

def send_request(code, body, cb)
  _connect
  syswrite format_request(code, next_sync, body)
  written = true
  response = _read_response
rescue ::Errno::EPIPE, Retry => e
  @socket = nil
  if !written && @retry && @reconnect
    @retry = false
    retry
  end
  cb.call Option.error(nil, Disconnected, e.message)
rescue StandardError => e
  cb.call Option.error(nil, e, nil)
else
  cb.call response
end