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

Instance Attribute Summary collapse

Attributes inherited from Mongo::Socket

#family, #options, #socket

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



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

def initialize(host, port, timeout, family, options = {})
  @host, @port, @timeout, @options = host, port, timeout, options
  super(family)
  connect!
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

#timeoutFloat (readonly)

Returns timeout The socket timeout.

Returns:

  • (Float)

    timeout The socket timeout.

Since:

  • 2.0.0



30
31
32
# File 'lib/mongo/socket/tcp.rb', line 30

def timeout
  @timeout
end