Class: Mongo::Socket::Unix

Inherits:
Mongo::Socket show all
Defined in:
lib/mongo/socket/unix.rb

Overview

Wrapper for Unix sockets.

Since:

  • 2.0.0

Constant Summary

Constants inherited from Mongo::Socket

SSL_ERROR, TIMEOUT_ERROR, TIMEOUT_PACK

Instance Attribute Summary collapse

Attributes inherited from Mongo::Socket

#family, #socket

Instance Method Summary collapse

Methods inherited from Mongo::Socket

#alive?, #close, #eof?, #gets, #read, #readbyte, #write

Constructor Details

#initialize(path, timeout) ⇒ Unix

Initializes a new Unix socket.

Examples:

Create the Unix socket.

Unix.new('/path/to.sock', 5)

Parameters:

  • path (String)

    The path.

  • timeout (Float)

    The socket timeout value.

Since:

  • 2.0.0



53
54
55
56
57
# File 'lib/mongo/socket/unix.rb', line 53

def initialize(path, timeout)
  @path, @timeout = path, timeout
  @socket = ::UNIXSocket.new(path)
  set_socket_options(@socket)
end

Instance Attribute Details

#pathString (readonly)

Returns path The path to connect to.

Returns:

  • (String)

    path The path to connect to.

Since:

  • 2.0.0



24
25
26
# File 'lib/mongo/socket/unix.rb', line 24

def path
  @path
end

#timeoutFloat (readonly)

Returns timeout The socket timeout.

Returns:

  • (Float)

    timeout The socket timeout.

Since:

  • 2.0.0



27
28
29
# File 'lib/mongo/socket/unix.rb', line 27

def timeout
  @timeout
end

Instance Method Details

#connect!(connect_timeout = nil) ⇒ Unix

Note:

This method mutates the object by setting the socket internally.

Establishes a socket connection.

Examples:

Connect the socket.

sock.connect!

Returns:

  • (Unix)

    The connected socket instance.

Since:

  • 2.0.0



40
41
42
# File 'lib/mongo/socket/unix.rb', line 40

def connect!(connect_timeout = nil)
  self
end

#connectable?true, false

This socket can only be used if the unix socket (@socket) has been created.

Examples:

Is the socket connectable?

socket.connectable?

Returns:

  • (true, false)

    If the socket is connectable.

Since:

  • 2.2.5



67
68
69
# File 'lib/mongo/socket/unix.rb', line 67

def connectable?
  !!@socket
end