Class: Mongo::Socket::TCP Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Mongo::Socket
|
|
Instance Chain:
self,
::Mongo::Socket ,
Socket::Constants
|
|
Inherits: |
Mongo::Socket
|
Defined in: | lib/mongo/socket/tcp.rb |
Overview
Wrapper for TCP
sockets.
Constant Summary
::Mongo::Socket
- Inherited
DEFAULT_TCP_KEEPCNT, DEFAULT_TCP_KEEPIDLE, DEFAULT_TCP_KEEPINTVL, DEFAULT_TCP_USER_TIMEOUT, SSL_ERROR, TIMEOUT_ERROR, TIMEOUT_PACK, WRITE_CHUNK_SIZE
Class Method Summary
-
.new(host, port, timeout, family, options = {}) ⇒ TCP
constructor
Internal use only
Internal use only
Initializes a new
TCP
socket.
::Mongo::Socket
- Inherited
.new | Initializes common socket attributes. |
Instance Attribute Summary
- #host ⇒ String readonly Internal use only
- #port ⇒ Integer readonly Internal use only
::Mongo::Socket
- Inherited
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
::Mongo::Socket
- Inherited
#close | Close the socket. |
#connection_address, #connection_generation, | |
#gets | Delegates gets to the underlying socket. |
#read | Will read all data from the socket for the provided number of bytes. |
#readbyte | Read a single byte from the socket. |
#summary, | |
#write | Writes data to the socket instance. |
#allocate_string, | |
#do_write | Writes data to the socket instance. |
#human_address, #map_exceptions, #raise_timeout_error!, #read_buffer_size, | |
#read_from_socket | Reads the |
#read_with_timeout | Reads the |
#read_without_timeout | Reads the |
#set_keepalive_opts, #set_option, #set_socket_options, #unix_socket?, #write_chunk, | |
#write_with_timeout | Writes data to to the socket, the write duration is limited to #timeout. |
#write_without_timeout | Writes data to to the socket. |
Instance Attribute Details
#host ⇒ String
(readonly)
# File 'lib/mongo/socket/tcp.rb', line 66
attr_reader :host
#port ⇒ Integer
(readonly)
# File 'lib/mongo/socket/tcp.rb', line 69
attr_reader :port
Instance Method Details
#connect! ⇒ TCP
This method mutates the object by setting the socket internally.
Establishes a socket connection.
# File 'lib/mongo/socket/tcp.rb', line 83
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)
# File 'lib/mongo/socket/tcp.rb', line 103
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)
# File 'lib/mongo/socket/tcp.rb', line 98
def connect_without_timeout(sockaddr) socket.connect(sockaddr) end