/// Initiate a connection from this socket to the given server socket.
///
/// The given `socket` must be in a listening state.
///
/// If there is enough room the listening socket's queue of incoming connections, this socket
/// is connected to a new socket, which is placed in the queue for the listening socket to
/// accept.
///
/// Returns an error if the connection cannot be established (e.g., if one of the sockets is
/// already connected).
Initiate a connection from this socket to the given server socket.
The given `socket` must be in a listening state.

If there is enough room the listening socket's queue of incoming connections, this socket
is connected to a new socket, which is placed in the queue for the listening socket to
accept.

Returns an error if the connection cannot be established .
Initiate a connection from this socket to the given server socket . The given ` socket ` must be in a listening state . If there is enough room the listening socket ' s queue of incoming connections this socket is connected to a new socket which is placed in the queue for the listening socket to accept . Returns an error if the connection cannot be established .
fn connect(
        &self,
        socket: &SocketHandle,
        peer: &SocketHandle,
        credentials: ucred,
    ) -> Result<(), Errno> {
        // Only hold one lock at a time until we make sure the lock ordering is right: client
        // before listener
        match peer.lock().state {
            SocketState::Listening(_) => {}
            _ => return error!(ECONNREFUSED),
        }
        let mut client = socket.lock();
        match client.state {
            SocketState::Disconnected => {}
            SocketState::Connected(_) => return error!(EISCONN),
            _ => return error!(EINVAL),
        };
        let mut listener = peer.lock();
        // Must check this again because we released the listener lock for a moment
        let queue = match &listener.state {
            SocketState::Listening(queue) => queue,
            _ => return error!(ECONNREFUSED),
        };
        socket.check_type_for_connect(peer, &listener.address)?;
        if queue.sockets.len() >= queue.backlog {
            return error!(EAGAIN);
        }
        let server = Socket::new(peer.domain, peer.socket_type);
        server.lock().messages.set_capacity(listener.messages.capacity())?;
        client.state = SocketState::Connected(server.clone());
        client.credentials = Some(credentials);
        {
            let mut server = server.lock();
            server.state = SocketState::Connected(socket.clone());
            server.address = listener.address.clone();
        }
        // We already checked that the socket is in Listening state...but the borrow checker cannot
        // be convinced that it's ok to combine these checks
        let queue = match listener.state {
            SocketState::Listening(ref mut queue) => queue,
            _ => panic!("something changed the server socket state while I held a lock on it"),
        };
        queue.sockets.push_back(server);
        listener.waiters.notify_events(FdEvents::POLLIN);
        Ok(())
    }
fn connect ( & self , socket : & SocketHandle , peer : & SocketHandle , credentials : ucred , ) -> Result < ( ) , Errno > { // Only hold one lock at a time until we make sure the lock ordering is right: client // before listener match peer . lock ( ) . state { SocketState :: Listening ( _ ) => { } _ => return error ! ( ECONNREFUSED ) , } let mut client = socket . lock ( ) ; match client . state { SocketState :: Disconnected => { } SocketState :: Connected ( _ ) => return error ! ( EISCONN ) , _ => return error ! ( EINVAL ) , } ; let mut listener = peer . lock ( ) ; // Must check this again because we released the listener lock for a moment let queue = match & listener . state { SocketState :: Listening ( queue ) => queue , _ => return error ! ( ECONNREFUSED ) , } ; socket . check_type_for_connect ( peer , & listener . address ) ? ; if queue . sockets . len ( ) >= queue . backlog { return error ! ( EAGAIN ) ; } let server = Socket :: new ( peer . domain , peer . socket_type ) ; server . lock ( ) . messages . set_capacity ( listener . messages . capacity ( ) ) ? ; client . state = SocketState :: Connected ( server . clone ( ) ) ; client . credentials = Some ( credentials ) ; { let mut server = server . lock ( ) ; server . state = SocketState :: Connected ( socket . clone ( ) ) ; server . address = listener . address . clone ( ) ; } // We already checked that the socket is in Listening state...but the borrow checker cannot // be convinced that it's ok to combine these checks let queue = match listener . state { SocketState :: Listening ( ref mut queue ) => queue , _ => panic ! ( " " ) , } ; queue . sockets . push_back ( server ) ; listener . waiters . notify_events ( FdEvents :: POLLIN ) ; Ok ( ( ) ) }
Initiate a connection from this socket to the given server socket.
Initiate a connection from this socket to the given server socket .
&self
socket
&SocketHandle
peer
&SocketHandle
credentials
ucred