lib/mongo/server/connection.rb
# Establishes a network connection to the target address.
#
# If the connection is already established, this method does nothing.
#
# @example Connect to the host.
#   connection.connect!
#
# @note This method mutates the connection object by setting a socket if
#   one previously did not exist.
#
# @return [ true ] If the connection succeeded.
#
# @since 2.0.0
Establishes a network connection to the target address.
If the connection is already established, this method does nothing.
Establishes a network connection to the target address . If the connection is already established this method does nothing .
def connect!
        if error?
          raise Error::ConnectionPerished, "Connection #{generation}:#{id} for #{address.seed} is perished. Reconnecting closed or errored connections is no longer supported"
        end
        if closed?
          raise Error::ConnectionPerished, "Connection #{generation}:#{id} for #{address.seed} is closed. Reconnecting closed or errored connections is no longer supported"
        end
        unless @socket
          @socket, @description, @compressor = do_connect
          if server.load_balancer?
            if Lint.enabled?
              unless service_id
                raise Error::InternalDriverError, "The connection is to a load balancer and it must have service_id set here, but does not"
              end
            end
            @generation = connection_pool.generation_manager.generation(service_id: service_id)
          end
          publish_cmap_event(
            Monitoring::Event::Cmap::ConnectionReady.new(address, id)
          )
          @close_event_published = false
        end
        true
      end
def connect! if error? raise Error :: ConnectionPerished , "Connection #{generation}:#{id} for #{address.seed} is perished. Reconnecting closed or errored connections is no longer supported" end if closed? raise Error :: ConnectionPerished , "Connection #{generation}:#{id} for #{address.seed} is closed. Reconnecting closed or errored connections is no longer supported" end unless @socket @socket , @description , @compressor = do_connect if server . load_balancer? if Lint . enabled? unless service_id raise Error :: InternalDriverError , "The connection is to a load balancer and it must have service_id set here, but does not" end end @generation = connection_pool . generation_manager . generation ( service_id : service_id ) end publish_cmap_event ( Monitoring :: Event :: Cmap :: ConnectionReady . new ( address , id ) ) @close_event_published = false end true end
Establishes a network connection to the target address.
Establishes a network connection to the target address .
# When @socket is assigned, the socket should have handshaken and # authenticated and be usable.
If the connection succeeded.
If the connection succeeded .
 true 
example
Connect to the host. connection.connect!
Connect to the host . connection . connect!
note
This method mutates the connection object by setting a socket if one previously did not exist.
This method mutates the connection object by setting a socket if one previously did not exist .
since
None