Class: Mongo::Socket::TCP
- Inherits:
-
Mongo::Socket
- Object
- Mongo::Socket
- Mongo::Socket::TCP
- Defined in:
- lib/mongo/socket/tcp.rb
Overview
Wrapper for TCP sockets.
Constant Summary
Constants inherited from Mongo::Socket
SSL_ERROR, TIMEOUT_ERROR, TIMEOUT_PACK
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
Host The host to connect to.
-
#port ⇒ Integer
readonly
Port The port to connect to.
-
#timeout ⇒ Float
readonly
Timeout The connection timeout.
Attributes inherited from Mongo::Socket
Instance Method Summary collapse
-
#connect! ⇒ TCP
Establishes a socket connection.
-
#initialize(host, port, timeout, family) ⇒ TCP
constructor
Initializes a new TCP socket.
Methods inherited from Mongo::Socket
#alive?, #close, #eof?, #gets, #read, #readbyte, #write
Constructor Details
#initialize(host, port, timeout, family) ⇒ TCP
Initializes a new TCP socket.
63 64 65 66 |
# File 'lib/mongo/socket/tcp.rb', line 63 def initialize(host, port, timeout, family) @host, @port, @timeout = host, port, timeout super(family) end |
Instance Attribute Details
#host ⇒ String (readonly)
Returns host The host to connect to.
24 25 26 |
# File 'lib/mongo/socket/tcp.rb', line 24 def host @host end |
#port ⇒ Integer (readonly)
Returns port The port to connect to.
27 28 29 |
# File 'lib/mongo/socket/tcp.rb', line 27 def port @port end |
#timeout ⇒ Float (readonly)
Returns timeout The connection timeout.
30 31 32 |
# File 'lib/mongo/socket/tcp.rb', line 30 def timeout @timeout end |
Instance Method Details
#connect! ⇒ TCP
Note:
This method mutates the object by setting the socket internally.
Establishes a socket connection.
43 44 45 46 47 48 49 |
# File 'lib/mongo/socket/tcp.rb', line 43 def connect! Timeout.timeout(timeout, Error::SocketTimeoutError) do socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) handle_errors { socket.connect(::Socket.pack_sockaddr_in(port, host)) } self end end |