Class: Mongo::Socket::TCP Private
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Socket
|
|
|
Instance Chain:
self,
Socket
|
|
| Inherits: |
Socket
|
| Defined in: | lib/mongo/socket/tcp.rb |
Overview
Wrapper for TCP sockets.
Class Method Summary
-
.new(host, port, timeout, family, options = {}) ⇒ TCP
constructor
Internal use only
Internal use only
Initializes a new
TCPsocket.
Instance Attribute Summary
- #host ⇒ String readonly Internal use only
- #port ⇒ Integer readonly Internal use only
Instance Method Summary
-
#connect! ⇒ TCP
Internal use only
Internal use only
Establishes a socket connection.
- #connect_with_timeout(sockaddr, connect_timeout) Internal use only Internal use only
- #connect_without_timeout(sockaddr) Internal use only Internal use only
- #human_address private Internal use only
Instance Attribute Details
#host ⇒ String (readonly)
# File 'lib/mongo/socket/tcp.rb', line 62
attr_reader :host
#port ⇒ Integer (readonly)
# File 'lib/mongo/socket/tcp.rb', line 65
attr_reader :port
Instance Method Details
#connect! ⇒ TCP
This method is for internal use only.
Note:
This method mutates the object by setting the socket internally.
Establishes a socket connection.
# File 'lib/mongo/socket/tcp.rb', line 79
def connect! socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) sockaddr = ::Socket.pack_sockaddr_in(port, host) connect_timeout = [:connect_timeout] map_exceptions do if connect_timeout && connect_timeout != 0 connect_with_timeout(sockaddr, connect_timeout) else connect_without_timeout(sockaddr) end end self end
#connect_with_timeout(sockaddr, connect_timeout)
This method is for internal use only.
# File 'lib/mongo/socket/tcp.rb', line 99
def connect_with_timeout(sockaddr, connect_timeout) if connect_timeout <= 0 raise Error::SocketTimeoutError, "The socket took over #{connect_timeout} seconds to connect" end deadline = Utils.monotonic_time + connect_timeout begin socket.connect_nonblock(sockaddr) rescue IO::WaitWritable select_timeout = deadline - Utils.monotonic_time if select_timeout <= 0 raise Error::SocketTimeoutError, "The socket took over #{connect_timeout} seconds to connect" end if IO.select(nil, [ socket ], nil, select_timeout) retry else socket.close raise Error::SocketTimeoutError, "The socket took over #{connect_timeout} seconds to connect" end rescue Errno::EISCONN # Socket is connected, nothing more to do end end
#connect_without_timeout(sockaddr)
This method is for internal use only.
# File 'lib/mongo/socket/tcp.rb', line 94
def connect_without_timeout(sockaddr) socket.connect(sockaddr) end