Class: Tarantool16::Connection::Dumb
- Inherits:
-
Object
- Object
- Tarantool16::Connection::Dumb
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, #_eval, #_init_common, #_insert, #_ipv6?, #_ping, #_replace, #_select, #_tcp?, #_unix?, #_unix_sock_path, #_update, #_upsert, #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.
14
15
16
17
18
19
|
# File 'lib/tarantool16/connection/dumb.rb', line 14
def initialize(host, opts = {})
_init_common(host, opts)
@reconnect_time = now_f - 1
@socket = nil
_connect
end
|
Instance Method Details
#close ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/tarantool16/connection/dumb.rb', line 48
def close
@reconnect = false
if @socket
@socket.close rescue nil
@socket = false
@s = 0
end
end
|
#connected? ⇒ Boolean
57
58
59
|
# File 'lib/tarantool16/connection/dumb.rb', line 57
def connected?
@socket
end
|
#could_be_connected? ⇒ Boolean
61
62
63
|
# File 'lib/tarantool16/connection/dumb.rb', line 61
def could_be_connected?
@socket || (@socket.nil? && (@reconnect || @reconnect_time < now_f))
end
|
#disconnect ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/tarantool16/connection/dumb.rb', line 40
def disconnect
if @socket
@socket.close rescue nil
@socket = nil
@s = 0
end
end
|
#send_request(code, body, cb) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/tarantool16/connection/dumb.rb', line 21
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.close rescue nil
@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
|