Class: Thrift::UNIXServerSocket

Inherits:
BaseServerTransport show all
Defined in:
lib/thrift/transport/unix_server_socket.rb

Constant Summary

Constants inherited from BaseServerTransport

BaseServerTransport::DEFAULT_CLIENT_TIMEOUT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, client_timeout: DEFAULT_CLIENT_TIMEOUT) ⇒ UNIXServerSocket

Returns a new instance of UNIXServerSocket.



26
27
28
29
30
# File 'lib/thrift/transport/unix_server_socket.rb', line 26

def initialize(path, client_timeout: DEFAULT_CLIENT_TIMEOUT)
  @path = path
  @client_timeout = client_timeout
  @handle = nil
end

Instance Attribute Details

#client_timeoutObject (readonly)

Returns the value of attribute client_timeout.



33
34
35
# File 'lib/thrift/transport/unix_server_socket.rb', line 33

def client_timeout
  @client_timeout
end

#handleObject Also known as: to_io

Returns the value of attribute handle.



32
33
34
# File 'lib/thrift/transport/unix_server_socket.rb', line 32

def handle
  @handle
end

Instance Method Details

#acceptObject



39
40
41
42
43
44
45
46
47
# File 'lib/thrift/transport/unix_server_socket.rb', line 39

def accept
  unless @handle.nil?
    sock = @handle.accept
    trans = UNIXSocket.new(nil)
    trans.timeout = @client_timeout
    trans.handle = sock
    trans
  end
end

#closeObject



49
50
51
52
53
54
55
56
# File 'lib/thrift/transport/unix_server_socket.rb', line 49

def close
  if @handle
    @handle.close unless @handle.closed?
    @handle = nil
    # UNIXServer doesn't delete the socket file, so we have to do it ourselves
    File.delete(@path)
  end
end

#closed?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/thrift/transport/unix_server_socket.rb', line 58

def closed?
  @handle.nil? or @handle.closed?
end

#listenObject



35
36
37
# File 'lib/thrift/transport/unix_server_socket.rb', line 35

def listen
  @handle = ::UNIXServer.new(@path)
end

#to_sObject



64
65
66
# File 'lib/thrift/transport/unix_server_socket.rb', line 64

def to_s
  "domain(#{@path})"
end