pub fn receive_from(&mut self, socket: &mut dyn Socket) -> Result<Vec<TParam::TReceive>> {
        let mut buffer = [0u8; 1024];
        let mut result = Vec::new();
        let mut had_message = false;
        loop {
            let receive_result = socket.recv_from(&mut buffer);
            let count = match receive_result {
                Ok((_, addr)) if addr != self.peer_addr => continue, // ignored
                Ok((count, _)) if count == 0 => {
                    if !had_message {
                        return Err(std::io::Error::from(ErrorKind::BrokenPipe).into());
                    } else {
                        return Ok(result);
                    }
                }
                Ok((count, _)) => count,
                Err(ref e) if e.kind() == ErrorKind::WouldBlock => return Ok(result),
                Err(e) => return Err(e.into()),
            };
            had_message = true;
            if let Some(msg) = self.handle_incoming_data(socket, &buffer[..count])? {
                result.push(msg);
            }
        }
    }
/// Receive data from the other connector. This will call `handle_incoming_data` internally.
///
/// Ideally you would never need this function. Use `update_and_receive` on clients, and `handle_incoming_data` on servers.
Receive data from the other connector. This will call `handle_incoming_data` internally.
Ideally you would never need this function. Use `update_and_receive` on clients, and `handle_incoming_data` on servers.
Receive data from the other connector . This will call ` handle_incoming_data ` internally . Ideally you would never need this function . Use ` update_and_receive ` on clients and ` handle_incoming_data ` on servers .
pub fn receive_from(&mut self, socket: &mut dyn Socket) -> Result<Vec<TParam::TReceive>> {
        let mut buffer = [0u8; 1024];
        let mut result = Vec::new();
        let mut had_message = false;
        loop {
            let receive_result = socket.recv_from(&mut buffer);
            let count = match receive_result {
                Ok((_, addr)) if addr != self.peer_addr => continue, // ignored
                Ok((count, _)) if count == 0 => {
                    if !had_message {
                        return Err(std::io::Error::from(ErrorKind::BrokenPipe).into());
                    } else {
                        return Ok(result);
                    }
                }
                Ok((count, _)) => count,
                Err(ref e) if e.kind() == ErrorKind::WouldBlock => return Ok(result),
                Err(e) => return Err(e.into()),
            };
            had_message = true;
            if let Some(msg) = self.handle_incoming_data(socket, &buffer[..count])? {
                result.push(msg);
            }
        }
    }
pub fn receive_from ( & mut self , socket : & mut dyn Socket ) -> Result < Vec < TParam :: TReceive > > { let mut buffer = [ 0u8 ; 1024 ] ; let mut result = Vec :: new ( ) ; let mut had_message = false ; loop { let receive_result = socket . recv_from ( & mut buffer ) ; let count = match receive_result { Ok ( ( _ , addr ) ) if addr != self . peer_addr => continue , // ignored Ok ( ( count , _ ) ) if count == 0 => { if ! had_message { return Err ( std :: io :: Error :: from ( ErrorKind :: BrokenPipe ) . into ( ) ) ; } else { return Ok ( result ) ; } } Ok ( ( count , _ ) ) => count , Err ( ref e ) if e . kind ( ) == ErrorKind :: WouldBlock => return Ok ( result ) , Err ( e ) => return Err ( e . into ( ) ) , } ; had_message = true ; if let Some ( msg ) = self . handle_incoming_data ( socket , & buffer [ .. count ] ) ? { result . push ( msg ) ; } } }
Receive data from the other connector.
Receive data from the other connector .
&mut self
socket
&mut dyn Socket
&mut self
socket
&mut dyn Socket