Class: Mongo::Socket::TCP Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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?, #connection_address, #connection_generation, #eof?, #gets, #monitor?, #read, #readbyte, #summary, #write

Constructor Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

  • :connection_address (Address)

    Address of the connection that created this socket.

  • :connection_generation (Integer)

    Generation of the connection (for non-monitoring connections) that created this socket.

  • :monitor (true | false)

    Whether this socket was created by a monitoring connection.

Since:

  • 2.0.0



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mongo/socket/tcp.rb', line 48

def initialize(host, port, timeout, family, options = {})
  if family.nil?
    raise ArgumentError, 'family must be specified'
  end
  super(timeout, options)
  @host, @port = host, port
  @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)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns host The host to connect to.

Returns:

  • (String)

    host The host to connect to.

Since:

  • 2.0.0



66
67
68
# File 'lib/mongo/socket/tcp.rb', line 66

def host
  @host
end

#portInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns port The port to connect to.

Returns:

  • (Integer)

    port The port to connect to.

Since:

  • 2.0.0



69
70
71
# File 'lib/mongo/socket/tcp.rb', line 69

def port
  @port
end