Class: Thrift::ServerSocket
Constant Summary
BaseServerTransport::DEFAULT_CLIENT_TIMEOUT
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(host_or_port, port = nil, client_timeout: DEFAULT_CLIENT_TIMEOUT) ⇒ ServerSocket
call-seq: initialize(host = nil, port, client_timeout: DEFAULT_CLIENT_TIMEOUT)
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/thrift/transport/server_socket.rb', line 27
def initialize(host_or_port, port = nil, client_timeout: DEFAULT_CLIENT_TIMEOUT)
if port
@host = host_or_port
@port = port
else
@host = nil
@port = host_or_port
end
@client_timeout = client_timeout
@handle = nil
end
|
Instance Attribute Details
#client_timeout ⇒ Object
Returns the value of attribute client_timeout.
39
40
41
|
# File 'lib/thrift/transport/server_socket.rb', line 39
def client_timeout
@client_timeout
end
|
#handle ⇒ Object
Returns the value of attribute handle.
39
40
41
|
# File 'lib/thrift/transport/server_socket.rb', line 39
def handle
@handle
end
|
Instance Method Details
#accept ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/thrift/transport/server_socket.rb', line 45
def accept
unless @handle.nil?
sock = @handle.accept
sock.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
trans = Socket.new
trans.timeout = @client_timeout
trans.handle = sock
trans
end
end
|
#close ⇒ Object
56
57
58
59
|
# File 'lib/thrift/transport/server_socket.rb', line 56
def close
@handle.close unless @handle.nil? or @handle.closed?
@handle = nil
end
|
#closed? ⇒ Boolean
61
62
63
|
# File 'lib/thrift/transport/server_socket.rb', line 61
def closed?
@handle.nil? or @handle.closed?
end
|
#listen ⇒ Object
41
42
43
|
# File 'lib/thrift/transport/server_socket.rb', line 41
def listen
@handle = TCPServer.new(@host, @port)
end
|
#to_io ⇒ Object
65
66
67
|
# File 'lib/thrift/transport/server_socket.rb', line 65
def to_io
@handle&.to_io || raise(IOError, 'closed stream')
end
|
#to_s ⇒ Object
69
70
71
|
# File 'lib/thrift/transport/server_socket.rb', line 69
def to_s
"socket(#{@host}:#{@port})"
end
|