fn handle_event(&mut self, fd: RawFd, event_set: EventSet) {
        debug!(
            "vsock: muxer processing event: fd={}, evset={:?}",
            fd, event_set
        );

        match self.listener_map.get_mut(&fd) {
            // This event needs to be forwarded to a `MuxerConnection` that is listening for
            // it.
            Some(EpollListener::Connection { key, evset: _ }) => {
                let key_copy = *key;
                // The handling of this event will most probably mutate the state of the
                // receiving connection. We'll need to check for new pending RX, event set
                // mutation, and all that, so we're wrapping the event delivery inside those
                // checks.
                self.apply_conn_mutation(key_copy, |conn| {
                    conn.notify(event_set);
                });
            }

            // A new host-initiated connection is ready to be accepted.
            Some(EpollListener::HostSock) => {
                if self.conn_map.len() == defs::MAX_CONNECTIONS {
                    // If we're already maxed-out on connections, we'll just accept and
                    // immediately discard this potentially new one.
                    warn!("vsock: connection limit reached; refusing new host connection");
                    self.host_sock.accept().map(|_| 0).unwrap_or(0);
                    return;
                }
                self.host_sock
                    .accept()
                    .map_err(Error::UnixAccept)
                    .and_then(|(stream, _)| {
                        stream
                            .set_nonblocking(true)
                            .map(|_| stream)
                            .map_err(Error::UnixAccept)
                    })
                    .and_then(|stream| {
                        // Before forwarding this connection to a listening AF_VSOCK socket on
                        // the guest side, we need to know the destination port. We'll read
                        // that port from a "connect" command received on this socket, so the
                        // next step is to ask to be notified the moment we can read from it.
                        self.add_listener(stream.as_raw_fd(), EpollListener::LocalStream(stream))
                    })
                    .unwrap_or_else(|err| {
                        warn!("vsock: unable to accept local connection: {:?}", err);
                    });
            }

            // Data is ready to be read from a host-initiated connection. That would be the
            // "connect" command that we're expecting.
            Some(EpollListener::LocalStream(_)) => {
                if let Some(EpollListener::LocalStream(mut stream)) = self.remove_listener(fd) {
                    Self::read_local_stream_port(&mut stream)
                        .map(|peer_port| (self.allocate_local_port(), peer_port))
                        .and_then(|(local_port, peer_port)| {
                            self.add_connection(
                                ConnMapKey {
                                    local_port,
                                    peer_port,
                                },
                                MuxerConnection::new_local_init(
                                    stream,
                                    uapi::VSOCK_HOST_CID,
                                    self.cid,
                                    local_port,
                                    peer_port,
                                ),
                            )
                        })
                        .unwrap_or_else(|err| {
                            info!("vsock: error adding local-init connection: {:?}", err);
                        })
                }
            }

            _ => {
                info!(
                    "vsock: unexpected event: fd={:?}, evset={:?}",
                    fd, event_set
                );
                METRICS.vsock.muxer_event_fails.inc();
            }
        }
    }
/// Handle/dispatch an epoll event to its listener.
Handle/dispatch an epoll event to its listener.
Handle / dispatch an epoll event to its listener .
fn handle_event(&mut self, fd: RawFd, event_set: EventSet) {
        debug!(
            "vsock: muxer processing event: fd={}, evset={:?}",
            fd, event_set
        );
        match self.listener_map.get_mut(&fd) {
            // This event needs to be forwarded to a `MuxerConnection` that is listening for
            // it.
            Some(EpollListener::Connection { key, evset: _ }) => {
                let key_copy = *key;
                // The handling of this event will most probably mutate the state of the
                // receiving connection. We'll need to check for new pending RX, event set
                // mutation, and all that, so we're wrapping the event delivery inside those
                // checks.
                self.apply_conn_mutation(key_copy, |conn| {
                    conn.notify(event_set);
                });
            }
            // A new host-initiated connection is ready to be accepted.
            Some(EpollListener::HostSock) => {
                if self.conn_map.len() == defs::MAX_CONNECTIONS {
                    // If we're already maxed-out on connections, we'll just accept and
                    // immediately discard this potentially new one.
                    warn!("vsock: connection limit reached; refusing new host connection");
                    self.host_sock.accept().map(|_| 0).unwrap_or(0);
                    return;
                }
                self.host_sock
                    .accept()
                    .map_err(Error::UnixAccept)
                    .and_then(|(stream, _)| {
                        stream
                            .set_nonblocking(true)
                            .map(|_| stream)
                            .map_err(Error::UnixAccept)
                    })
                    .and_then(|stream| {
                        // Before forwarding this connection to a listening AF_VSOCK socket on
                        // the guest side, we need to know the destination port. We'll read
                        // that port from a "connect" command received on this socket, so the
                        // next step is to ask to be notified the moment we can read from it.
                        self.add_listener(stream.as_raw_fd(), EpollListener::LocalStream(stream))
                    })
                    .unwrap_or_else(|err| {
                        warn!("vsock: unable to accept local connection: {:?}", err);
                    });
            }
            // Data is ready to be read from a host-initiated connection. That would be the
            // "connect" command that we're expecting.
            Some(EpollListener::LocalStream(_)) => {
                if let Some(EpollListener::LocalStream(mut stream)) = self.remove_listener(fd) {
                    Self::read_local_stream_port(&mut stream)
                        .map(|peer_port| (self.allocate_local_port(), peer_port))
                        .and_then(|(local_port, peer_port)| {
                            self.add_connection(
                                ConnMapKey {
                                    local_port,
                                    peer_port,
                                },
                                MuxerConnection::new_local_init(
                                    stream,
                                    uapi::VSOCK_HOST_CID,
                                    self.cid,
                                    local_port,
                                    peer_port,
                                ),
                            )
                        })
                        .unwrap_or_else(|err| {
                            info!("vsock: error adding local-init connection: {:?}", err);
                        })
                }
            }
            _ => {
                info!(
                    "vsock: unexpected event: fd={:?}, evset={:?}",
                    fd, event_set
                );
                METRICS.vsock.muxer_event_fails.inc();
            }
        }
    }
fn handle_event ( & mut self , fd : RawFd , event_set : EventSet ) { debug ! ( " " fd event_set ) ; match self . listener_map . get_mut ( & fd ) { // This event needs to be forwarded to a `MuxerConnection` that is listening for // it. Some ( EpollListener :: Connection { key , evset : _ } ) => { let key_copy = * key ; // The handling of this event will most probably mutate the state of the // receiving connection. We'll need to check for new pending RX, event set // mutation, and all that, so we're wrapping the event delivery inside those // checks. self . apply_conn_mutation ( key_copy , | conn | { conn . notify ( event_set ) ; } ) ; } // A new host-initiated connection is ready to be accepted. Some ( EpollListener :: HostSock ) => { if self . conn_map . len ( ) == defs :: MAX_CONNECTIONS { // If we're already maxed-out on connections, we'll just accept and // immediately discard this potentially new one. warn ! ( " " ) ; self . host_sock . accept ( ) . map ( | _ | 0 ) . unwrap_or ( 0 ) ; return ; } self . host_sock . accept ( ) . map_err ( Error :: UnixAccept ) . and_then ( | ( stream , _ ) | { stream . set_nonblocking ( true ) . map ( | _ | stream ) . map_err ( Error :: UnixAccept ) } ) . and_then ( | stream | { // Before forwarding this connection to a listening AF_VSOCK socket on // the guest side, we need to know the destination port. We'll read // that port from a "connect" command received on this socket, so the // next step is to ask to be notified the moment we can read from it. self . add_listener ( stream . as_raw_fd ( ) , EpollListener :: LocalStream ( stream ) ) } ) . unwrap_or_else ( | err | { warn ! ( " " err ) ; } ) ; } // Data is ready to be read from a host-initiated connection. That would be the // "connect" command that we're expecting. Some ( EpollListener :: LocalStream ( _ ) ) => { if let Some ( EpollListener :: LocalStream ( mut stream ) ) = self . remove_listener ( fd ) { Self :: read_local_stream_port ( & mut stream ) . map ( | peer_port | ( self . allocate_local_port ( ) , peer_port ) ) . and_then ( | ( local_port , peer_port ) | { self . add_connection ( ConnMapKey { local_port , peer_port , } , MuxerConnection :: new_local_init ( stream , uapi :: VSOCK_HOST_CID , self . cid , local_port , peer_port , ) , ) } ) . unwrap_or_else ( | err | { info ! ( " " err ) ; } ) } } _ => { info ! ( " " fd event_set ) ; METRICS . vsock . muxer_event_fails . inc ( ) ; } } }
Handle/dispatch an epoll event to its listener.
Handle / dispatch an epoll event to its listener .
&mut self
fd
RawFd
event_set
EventSet
&mut self
fd
RawFd
event_set
EventSet