Class Mongo::Socket
In: lib/mongo/socket/ssl.rb
lib/mongo/socket/tcp.rb
lib/mongo/socket/unix.rb
lib/mongo/socket.rb
Parent: Object

Provides additional data around sockets for the driver‘s use.

@since 2.0.0

Methods

alive?   close   connectable?   eof?   gets   new   read   readbyte   write  

Included Modules

::Socket::Constants

Classes and Modules

Class Mongo::Socket::SSL
Class Mongo::Socket::TCP
Class Mongo::Socket::Unix

Constants

SSL_ERROR = 'MongoDB may not be configured with SSL support'.freeze   Error message for SSL related exceptions.

@since 2.0.0

TIMEOUT_ERROR = 'Socket request timed out'.freeze   Error message for timeouts on socket calls.

@since 2.0.0 @deprecated

TIMEOUT_PACK = 'l_2'.freeze   The pack directive for timeouts.

@since 2.0.0

DEFAULT_TCP_KEEPINTVL = 10
DEFAULT_TCP_KEEPCNT = 9
DEFAULT_TCP_KEEPIDLE = 300

Attributes

family  [R]  @return [ Integer ] family The type of host family.
options  [R]  @return [ Hash ] The options.
socket  [R]  @return [ Socket ] socket The wrapped socket.

Public Class methods

Create the new socket for the provided family - ipv4, piv6, or unix.

@example Create a new ipv4 socket.

  Socket.new(Socket::PF_INET)

@param [ Integer ] family The socket domain.

@since 2.0.0

Public Instance methods

Is the socket connection alive?

@example Is the socket alive?

  socket.alive?

@return [ true, false ] If the socket is alive.

@deprecated Use connectable? on the connection instead.

Close the socket.

@example Close the socket.

  socket.close

@return [ true ] Always true.

@since 2.0.0

For backwards compatibilty only, do not use.

@return [ true ] Always true.

@deprecated

Tests if this socket has reached EOF. Primarily used for liveness checks.

@since 2.0.5

Delegates gets to the underlying socket.

@example Get the next line.

  socket.gets(10)

@param [ Array<Object> ] args The arguments to pass through.

@return [ Object ] The returned bytes.

@since 2.0.0

Will read all data from the socket for the provided number of bytes. If no data is returned, an exception will be raised.

@example Read all the requested data from the socket.

  socket.read(4096)

@param [ Integer ] length The number of bytes to read.

@raise [ Mongo::SocketError ] If not all data is returned.

@return [ Object ] The data from the socket.

@since 2.0.0

Read a single byte from the socket.

@example Read a single byte.

  socket.readbyte

@return [ Object ] The read byte.

@since 2.0.0

Writes data to the socket instance.

@example Write to the socket.

  socket.write(data)

@param [ Array<Object> ] args The data to be written.

@return [ Integer ] The length of bytes written to the socket.

@since 2.0.0

[Validate]