Class: Mongo::Socket::TCP

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

Overview

Wrapper for TCP sockets.

Since:

  • 2.0.0

Constant Summary

Constants inherited from Mongo::Socket

SSL_ERROR, TIMEOUT_ERROR, TIMEOUT_PACK, WRITE_CHUNK_SIZE

Instance Attribute Summary collapse

Attributes inherited from Mongo::Socket

#family, #options, #socket, #timeout

Instance Method Summary collapse

Methods inherited from Mongo::Socket

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

Constructor Details

#initialize(host, port, timeout, family, options = {}) ⇒ TCP

Initializes a new TCP socket.

Examples:

Create the TCP socket.

TCP.new('::1', 27017, 30, Socket::PF_INET)
TCP.new('127.0.0.1', 27017, 30, Socket::PF_INET)

Parameters:

  • host (String)

    The hostname or IP address.

  • port (Integer)

    The port number.

  • timeout (Float)

    The socket timeout value.

  • family (Integer)

    The socket family.

  • options (Hash) (defaults to: {})

    The options.

Options Hash (options):

  • :connect_timeout (Float)

    Connect timeout.

Since:

  • 2.0.0



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mongo/socket/tcp.rb', line 66

def initialize(host, port, timeout, family, options = {})
  @host, @port, @timeout, @options = host, port, timeout, options
  @family = family
  @socket = ::Socket.new(family, SOCK_STREAM, 0)
  begin
    set_socket_options(@socket)
    connect!
  rescue
    @socket.close
    raise
  end
end

Instance Attribute Details

#hostString (readonly)

Returns host The host to connect to.

Returns:

  • (String)

    host The host to connect to.

Since:

  • 2.0.0



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

def host
  @host
end

#portInteger (readonly)

Returns port The port to connect to.

Returns:

  • (Integer)

    port The port to connect to.

Since:

  • 2.0.0



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

def port
  @port
end