pub fn read(&self, peek: bool, data: &mut [u8]) -> ZxResult<usize> {
        let curr_size = self.inner.lock().data.len();
        if curr_size == 0 {
            let _peer = self.peer.upgrade().ok_or(ZxError::PEER_CLOSED)?;
            let inner = self.inner.lock();
            if inner.read_disabled {
                return Err(ZxError::BAD_STATE);
            }
            return Err(ZxError::SHOULD_WAIT);
        }
        let was_full = curr_size == SOCKET_SIZE;
        let actual_count = if self.flags.contains(SocketFlags::DATAGRAM) {
            self.read_datagram(data, peek)?
        } else {
            self.read_stream(data, peek)?
        };
        if !peek && actual_count > 0 {
            let inner = self.inner.lock();
            let mut clear = Signal::empty();
            if inner.read_threshold > 0 && inner.data.len() < inner.read_threshold {
                clear |= Signal::SOCKET_READ_THRESHOLD;
            }
            if inner.data.is_empty() {
                clear |= Signal::READABLE;
            }
            self.base.signal_clear(clear);
            if let Ok(peer) = self.peer.upgrade().ok_or(ZxError::PEER_CLOSED) {
                let mut set = Signal::empty();
                let peer_inner = peer.inner.lock();
                if peer_inner.write_threshold > 0
                    && SOCKET_SIZE - inner.data.len() >= peer_inner.write_threshold
                {
                    set |= Signal::SOCKET_WRITE_THRESHOLD;
                }
                if was_full {
                    set |= Signal::WRITABLE;
                }
                peer.base.signal_set(set);
            }
        }
        Ok(actual_count)
    }
/// Read data from the socket. If successful, the number of bytes actually read are returned.
///
/// If the socket was created with **SOCKET_DATAGRAM**, this method reads
/// only the first available datagram in the socket (if one is present).
/// If *data* is too small for the datagram, then the read will be
/// truncated, and any remaining bytes in the datagram will be discarded.
///
/// If `peek` is true, leave the message in the socket. Otherwise consume the message.
Read data from the socket. If successful, the number of bytes actually read are returned.
If the socket was created with **SOCKET_DATAGRAM**, this method reads
only the first available datagram in the socket (if one is present).
If *data* is too small for the datagram, then the read will be
truncated, and any remaining bytes in the datagram will be discarded.

If `peek` is true, leave the message in the socket. Otherwise consume the message.
Read data from the socket . If successful the number of bytes actually read are returned . If the socket was created with ** SOCKET_DATAGRAM ** this method reads only the first available datagram in the socket ( if one is present ) . If * data * is too small for the datagram then the read will be truncated and any remaining bytes in the datagram will be discarded . If ` peek ` is true leave the message in the socket . Otherwise consume the message .
pub fn read(&self, peek: bool, data: &mut [u8]) -> ZxResult<usize> {
        let curr_size = self.inner.lock().data.len();
        if curr_size == 0 {
            let _peer = self.peer.upgrade().ok_or(ZxError::PEER_CLOSED)?;
            let inner = self.inner.lock();
            if inner.read_disabled {
                return Err(ZxError::BAD_STATE);
            }
            return Err(ZxError::SHOULD_WAIT);
        }
        let was_full = curr_size == SOCKET_SIZE;
        let actual_count = if self.flags.contains(SocketFlags::DATAGRAM) {
            self.read_datagram(data, peek)?
        } else {
            self.read_stream(data, peek)?
        };
        if !peek && actual_count > 0 {
            let inner = self.inner.lock();
            let mut clear = Signal::empty();
            if inner.read_threshold > 0 && inner.data.len() < inner.read_threshold {
                clear |= Signal::SOCKET_READ_THRESHOLD;
            }
            if inner.data.is_empty() {
                clear |= Signal::READABLE;
            }
            self.base.signal_clear(clear);
            if let Ok(peer) = self.peer.upgrade().ok_or(ZxError::PEER_CLOSED) {
                let mut set = Signal::empty();
                let peer_inner = peer.inner.lock();
                if peer_inner.write_threshold > 0
                    && SOCKET_SIZE - inner.data.len() >= peer_inner.write_threshold
                {
                    set |= Signal::SOCKET_WRITE_THRESHOLD;
                }
                if was_full {
                    set |= Signal::WRITABLE;
                }
                peer.base.signal_set(set);
            }
        }
        Ok(actual_count)
    }
pub fn read ( & self , peek : bool , data : & mut [ u8 ] ) -> ZxResult < usize > { let curr_size = self . inner . lock ( ) . data . len ( ) ; if curr_size == 0 { let _peer = self . peer . upgrade ( ) . ok_or ( ZxError :: PEER_CLOSED ) ? ; let inner = self . inner . lock ( ) ; if inner . read_disabled { return Err ( ZxError :: BAD_STATE ) ; } return Err ( ZxError :: SHOULD_WAIT ) ; } let was_full = curr_size == SOCKET_SIZE ; let actual_count = if self . flags . contains ( SocketFlags :: DATAGRAM ) { self . read_datagram ( data , peek ) ? } else { self . read_stream ( data , peek ) ? } ; if ! peek && actual_count > 0 { let inner = self . inner . lock ( ) ; let mut clear = Signal :: empty ( ) ; if inner . read_threshold > 0 && inner . data . len ( ) < inner . read_threshold { clear |= Signal :: SOCKET_READ_THRESHOLD ; } if inner . data . is_empty ( ) { clear |= Signal :: READABLE ; } self . base . signal_clear ( clear ) ; if let Ok ( peer ) = self . peer . upgrade ( ) . ok_or ( ZxError :: PEER_CLOSED ) { let mut set = Signal :: empty ( ) ; let peer_inner = peer . inner . lock ( ) ; if peer_inner . write_threshold > 0 && SOCKET_SIZE - inner . data . len ( ) >= peer_inner . write_threshold { set |= Signal :: SOCKET_WRITE_THRESHOLD ; } if was_full { set |= Signal :: WRITABLE ; } peer . base . signal_set ( set ) ; } } Ok ( actual_count ) }
Read data from the socket.
Read data from the socket .
&self
peek
bool
data
&mut [u8]
&self
peek
bool
data
&mut [u8]