fn send_bytes(
        &mut self,
        mem: &GuestMemoryMmap,
        pkt: &VsockPacket,
    ) -> std::result::Result<(), VsockError> {
        let len = pkt.len() as usize;

        // If there is data in the TX buffer, that means we're already registered for EPOLLOUT
        // events on the underlying stream. Therefore, there's no point in attempting a write
        // at this point. `self.notify()` will get called when EPOLLOUT arrives, and it will
        // attempt to drain the TX buffer then.
        if !self.tx_buf.is_empty() {
            return pkt
                .write_from_offset_to(mem, 0, &mut self.tx_buf, len)
                .map(|_| ());
        }

        // The TX buffer is empty, so we can try to write straight to the host stream.
        let written = match pkt.write_from_offset_to(mem, 0, &mut self.stream, len) {
            Ok(cnt) => cnt,
            Err(VsockError::GuestMemoryMmap(GuestMemoryError::IOError(e)))
                if e.kind() == ErrorKind::WouldBlock =>
            {
                // Absorb any would-block errors, since we can always try again later.
                0
            }
            Err(e) => {
                // We don't know how to handle any other write error, so we'll send it up
                // the call chain.
                METRICS.vsock.tx_write_fails.inc();
                return Err(e);
            }
        };
        // Move the "forwarded bytes" counter ahead by how much we were able to send out.
        self.fwd_cnt += Wrapping(written as u32);
        METRICS.vsock.tx_bytes_count.add(written);

        // If we couldn't write the whole slice, we'll need to push the remaining data to our
        // buffer.
        if written < len {
            pkt.write_from_offset_to(mem, written, &mut self.tx_buf, len - written)?;
        }

        Ok(())
    }
/// Send some raw data (a byte-slice) to the host stream.
///
/// Raw data can either be sent straight to the host stream, or to our TX buffer, if the
/// former fails.
Send some raw data (a byte-slice) to the host stream.
Raw data can either be sent straight to the host stream, or to our TX buffer, if the
former fails.
Send some raw data ( a byte - slice ) to the host stream . Raw data can either be sent straight to the host stream or to our TX buffer if the former fails .
fn send_bytes(
        &mut self,
        mem: &GuestMemoryMmap,
        pkt: &VsockPacket,
    ) -> std::result::Result<(), VsockError> {
        let len = pkt.len() as usize;
        // If there is data in the TX buffer, that means we're already registered for EPOLLOUT
        // events on the underlying stream. Therefore, there's no point in attempting a write
        // at this point. `self.notify()` will get called when EPOLLOUT arrives, and it will
        // attempt to drain the TX buffer then.
        if !self.tx_buf.is_empty() {
            return pkt
                .write_from_offset_to(mem, 0, &mut self.tx_buf, len)
                .map(|_| ());
        }
        // The TX buffer is empty, so we can try to write straight to the host stream.
        let written = match pkt.write_from_offset_to(mem, 0, &mut self.stream, len) {
            Ok(cnt) => cnt,
            Err(VsockError::GuestMemoryMmap(GuestMemoryError::IOError(e)))
                if e.kind() == ErrorKind::WouldBlock =>
            {
                // Absorb any would-block errors, since we can always try again later.
                0
            }
            Err(e) => {
                // We don't know how to handle any other write error, so we'll send it up
                // the call chain.
                METRICS.vsock.tx_write_fails.inc();
                return Err(e);
            }
        };
        // Move the "forwarded bytes" counter ahead by how much we were able to send out.
        self.fwd_cnt += Wrapping(written as u32);
        METRICS.vsock.tx_bytes_count.add(written);
        // If we couldn't write the whole slice, we'll need to push the remaining data to our
        // buffer.
        if written < len {
            pkt.write_from_offset_to(mem, written, &mut self.tx_buf, len - written)?;
        }
        Ok(())
    }
fn send_bytes ( & mut self , mem : & GuestMemoryMmap , pkt : & VsockPacket , ) -> std :: result :: Result < ( ) , VsockError > { let len = pkt . len ( ) as usize ; // If there is data in the TX buffer, that means we're already registered for EPOLLOUT // events on the underlying stream. Therefore, there's no point in attempting a write // at this point. `self.notify()` will get called when EPOLLOUT arrives, and it will // attempt to drain the TX buffer then. if ! self . tx_buf . is_empty ( ) { return pkt . write_from_offset_to ( mem , 0 , & mut self . tx_buf , len ) . map ( | _ | ( ) ) ; } // The TX buffer is empty, so we can try to write straight to the host stream. let written = match pkt . write_from_offset_to ( mem , 0 , & mut self . stream , len ) { Ok ( cnt ) => cnt , Err ( VsockError :: GuestMemoryMmap ( GuestMemoryError :: IOError ( e ) ) ) if e . kind ( ) == ErrorKind :: WouldBlock => { // Absorb any would-block errors, since we can always try again later. 0 } Err ( e ) => { // We don't know how to handle any other write error, so we'll send it up // the call chain. METRICS . vsock . tx_write_fails . inc ( ) ; return Err ( e ) ; } } ; // Move the "forwarded bytes" counter ahead by how much we were able to send out. self . fwd_cnt += Wrapping ( written as u32 ) ; METRICS . vsock . tx_bytes_count . add ( written ) ; // If we couldn't write the whole slice, we'll need to push the remaining data to our // buffer. if written < len { pkt . write_from_offset_to ( mem , written , & mut self . tx_buf , len - written ) ? ; } Ok ( ( ) ) }
Send some raw data (a byte-slice) to the host stream.
Send some raw data ( a byte - slice ) to the host stream .
&mut self
mem
&GuestMemoryMmap
pkt
&VsockPacket
&mut self
mem
&GuestMemoryMmap
pkt
&VsockPacket