def read(length)
      handle_errors do
        data = read_from_socket(length)
        raise IOError unless (data.length > 0 || length == 0)
        while data.length < length
          chunk = read_from_socket(length - data.length)
          raise IOError unless (chunk.length > 0 || length == 0)
          data << chunk
        end
        data
      end
    end
def read(length)
      handle_errors do
        data = read_from_socket(length)
        raise IOError unless (data.length > 0 || length == 0)
        while data.length < length
          chunk = read_from_socket(length - data.length)
          raise IOError unless (chunk.length > 0 || length == 0)
          data << chunk
        end
        data
      end
    end
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
 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