Class: JRPC::Transport::SocketBase
- Inherits:
-
Object
- Object
- JRPC::Transport::SocketBase
show all
- Defined in:
- lib/jrpc/transport/socket_base.rb
Defined Under Namespace
Classes: ConnectionFailedError, ConnectionTimeoutError, Error, ReadTimeoutError, TimeoutError, WriteTimeoutError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ SocketBase
Returns a new instance of SocketBase.
35
36
37
38
39
40
41
42
|
# File 'lib/jrpc/transport/socket_base.rb', line 35
def initialize(options)
@server = options.fetch(:server)
@read_timeout = options.fetch(:read_timeout, nil)
@write_timeout = options.fetch(:write_timeout, nil)
@connect_timeout = options.fetch(:connect_timeout, nil)
@connect_retry_count = options.fetch(:connect_retry_count, 0)
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
26
27
28
|
# File 'lib/jrpc/transport/socket_base.rb', line 26
def options
@options
end
|
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
26
27
28
|
# File 'lib/jrpc/transport/socket_base.rb', line 26
def read_timeout
@read_timeout
end
|
#write_timeout ⇒ Object
Returns the value of attribute write_timeout.
26
27
28
|
# File 'lib/jrpc/transport/socket_base.rb', line 26
def write_timeout
@write_timeout
end
|
Class Method Details
.connect(options) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/jrpc/transport/socket_base.rb', line 28
def self.connect(options)
connection = new(options)
yield(connection)
ensure
connection.close if connection
end
|
Instance Method Details
#close ⇒ Object
66
67
68
|
# File 'lib/jrpc/transport/socket_base.rb', line 66
def close
raise NotImplementedError
end
|
#closed? ⇒ Boolean
70
71
72
|
# File 'lib/jrpc/transport/socket_base.rb', line 70
def closed?
raise NotImplementedError
end
|
#connect ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/jrpc/transport/socket_base.rb', line 44
def connect
retries = @connect_retry_count
while retries >= 0
begin
connect_socket
break
rescue Error => e
retries -= 1
raise e if retries < 0
end
end
end
|
#read(_length, _timeout = @read_timeout) ⇒ Object
58
59
60
|
# File 'lib/jrpc/transport/socket_base.rb', line 58
def read(_length, _timeout = @read_timeout)
raise NotImplementedError
end
|
#write(_data, _timeout = @write_timeout) ⇒ Object
62
63
64
|
# File 'lib/jrpc/transport/socket_base.rb', line 62
def write(_data, _timeout = @write_timeout)
raise NotImplementedError
end
|