pub async fn step(&mut self) -> Result<Vec<tl::enums::Updates>, ReadError> {
        self.try_fill_write();

        // TODO probably want to properly set the request state on disconnect (read fail)

        let write_len = self.write_buffer.len() - self.write_index;

        let (mut reader, mut writer) = self.stream.split();
        if self.write_buffer.is_empty() {
            // TODO this always has to read the header of the packet and then the rest (2 or more calls)
            // it would be better to always perform calls in a circular buffer to have as much data from
            // the network as possible at all times, not just reading what's needed
            // (perhaps something similar could be done with the write buffer to write packet after packet)
            //
            // The `request_rx.recv()` can't return `None` because we're holding a `tx`.
            trace!("reading bytes from the network");
            tokio::select!(
                request = self.request_rx.recv() => {
                    self.requests.push(request.unwrap());
                    Ok(Vec::new())
                },
                n = reader.read_buf(&mut self.read_buffer) => {
                    self.on_net_read(n?)
                },
                _ = sleep_until(self.next_ping) => {
                    self.on_ping_timeout();
                    Ok(Vec::new())
                }
            )
        } else {
            trace!(
                "reading bytes and sending up to {} bytes via network",
                write_len
            );
            tokio::select! {
                request = self.request_rx.recv() => {
                    self.requests.push(request.unwrap());
                    Ok(Vec::new())
                },
                n = reader.read_buf(&mut self.read_buffer) => {
                    self.on_net_read(n?)
                }
                n = writer.write(&self.write_buffer[self.write_index..]) => {
                    self.on_net_write(n?);
                    Ok(Vec::new())
                }
                _ = sleep_until(self.next_ping) => {
                    self.on_ping_timeout();
                    Ok(Vec::new())
                }
            }
        }
    }
/// Step network events, writing and reading at the same time.
///
/// Updates received during this step, if any, are returned.
Step network events, writing and reading at the same time.
Updates received during this step, if any, are returned.
Step network events writing and reading at the same time . Updates received during this step if any are returned .
pub async fn step(&mut self) -> Result<Vec<tl::enums::Updates>, ReadError> {
        self.try_fill_write();
        // TODO probably want to properly set the request state on disconnect (read fail)
        let write_len = self.write_buffer.len() - self.write_index;
        let (mut reader, mut writer) = self.stream.split();
        if self.write_buffer.is_empty() {
            // TODO this always has to read the header of the packet and then the rest (2 or more calls)
            // it would be better to always perform calls in a circular buffer to have as much data from
            // the network as possible at all times, not just reading what's needed
            // (perhaps something similar could be done with the write buffer to write packet after packet)
            //
            // The `request_rx.recv()` can't return `None` because we're holding a `tx`.
            trace!("reading bytes from the network");
            tokio::select!(
                request = self.request_rx.recv() => {
                    self.requests.push(request.unwrap());
                    Ok(Vec::new())
                },
                n = reader.read_buf(&mut self.read_buffer) => {
                    self.on_net_read(n?)
                },
                _ = sleep_until(self.next_ping) => {
                    self.on_ping_timeout();
                    Ok(Vec::new())
                }
            )
        } else {
            trace!(
                "reading bytes and sending up to {} bytes via network",
                write_len
            );
            tokio::select! {
                request = self.request_rx.recv() => {
                    self.requests.push(request.unwrap());
                    Ok(Vec::new())
                },
                n = reader.read_buf(&mut self.read_buffer) => {
                    self.on_net_read(n?)
                }
                n = writer.write(&self.write_buffer[self.write_index..]) => {
                    self.on_net_write(n?);
                    Ok(Vec::new())
                }
                _ = sleep_until(self.next_ping) => {
                    self.on_ping_timeout();
                    Ok(Vec::new())
                }
            }
        }
    }
pub async fn step ( & mut self ) -> Result < Vec < tl :: enums :: Updates > , ReadError > { self . try_fill_write ( ) ; // TODO probably want to properly set the request state on disconnect (read fail) let write_len = self . write_buffer . len ( ) - self . write_index ; let ( mut reader , mut writer ) = self . stream . split ( ) ; if self . write_buffer . is_empty ( ) { // TODO this always has to read the header of the packet and then the rest (2 or more calls) // it would be better to always perform calls in a circular buffer to have as much data from // the network as possible at all times, not just reading what's needed // (perhaps something similar could be done with the write buffer to write packet after packet) // // The `request_rx.recv()` can't return `None` because we're holding a `tx`. trace ! ( " " ) ; tokio :: select ! ( request self request_rx recv ( ) { self requests push ( request unwrap ( ) ) Ok ( Vec new ( ) ) } n reader read_buf ( mut self read_buffer ) { self on_net_read ( n ) } sleep_until ( self next_ping ) { self on_ping_timeout ( ) Ok ( Vec new ( ) ) } ) } else { trace ! ( " " write_len ) ; tokio :: select ! { request self request_rx recv ( ) { self requests push ( request unwrap ( ) ) Ok ( Vec new ( ) ) } n reader read_buf ( mut self read_buffer ) { self on_net_read ( n ) } n writer write ( self write_buffer [ self write_index ] ) { self on_net_write ( n ) Ok ( Vec new ( ) ) } sleep_until ( self next_ping ) { self on_ping_timeout ( ) Ok ( Vec new ( ) ) } } } }
Step network events, writing and reading at the same time.
Step network events writing and reading at the same time .
&mut self
&mut self