Required method
(mut self: Pin<&mut Self>, ctx: &mut Context<'_>)
| 861 | |
| 862 | // Required method |
| 863 | fn poll_next(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Option<Self::Item>> { |
| 864 | // We have hit the buffer full limit, so drain some first. This only happens if the |
| 865 | // buffer is misaligned as we proceed through the download, and we managed to |
| 866 | // build up a ton of data that didn't align on frame boundaries. |
| 867 | if self.as_mut().project().buffer.len() >= BUFFER_NET_LIMIT { |
| 868 | let buf_to_send = self.as_mut().project().buffer.split_to(BUFFER_MIN_XMIT); |
| 869 | let buf = Bytes::from(buf_to_send); |
| 870 | return Poll::Ready(Some(Ok(buf))); |
| 871 | } |
| 872 | |
| 873 | // Buffer must not have more than BUFFER_NET_LIMIT in it now, so we can read a bit more. |
| 874 | loop { |
| 875 | match self.as_mut().project().dlos_reader.poll_next(ctx) { |
| 876 | Poll::Ready(Some(Ok(buf))) => { |
| 877 | // Buffer the content. We don't want to spend too much time buffering, so we |
| 878 | // only buffer a small amount at a time. |
| 879 | self.as_mut().project().buffer.extend_from_slice(&buf); |
| 880 | // We want at least this much data in the buffer to proceed, this is divisible |
| 881 | // by frames. Leftover content will be dealt with next Poll. |
| 882 | if self.as_mut().project().buffer.len() >= BUFFER_NET_LIMIT { |
| 883 | let buf_to_send = self.as_mut().project().buffer.split_to(BUFFER_MIN_XMIT); |
| 884 | |
| 885 | let buf = Bytes::from(buf_to_send); |
| 886 | break Poll::Ready(Some(Ok(buf))); |
| 887 | } else { |
| 888 | // Fill more!!! |
| 889 | continue; |
| 890 | } |
| 891 | } |
| 892 | // Error |
| 893 | Poll::Ready(Some(Err(e))) => break Poll::Ready(Some(Err(e))), |
| 894 | // Indicates termination of the stream. We are DONE!!! |
| 895 | Poll::Ready(None) => { |
| 896 | if self.as_mut().project().buffer.is_empty() { |
| 897 | break Poll::Ready(None); |
| 898 | } else { |
| 899 | // Send out all remaining bytes, yolo. |
| 900 | let buf = self.as_mut().project().buffer.split().freeze(); |
| 901 | break Poll::Ready(Some(Ok(buf))); |
| 902 | } |
| 903 | } |
| 904 | // Pending on more bytes from upstream. |
| 905 | Poll::Pending => { |
| 906 | // TODO: Does this break things? |
| 907 | // WAS - break Poll::Pending |
| 908 | // |
| 909 | // Okay, we're pending on upstream bytes, but do we have anything to send? This way |
| 910 | // we don't block out the reader. This can happen if during a tight Poll::Ready |
| 911 | // loop, we ended up in a Pending from upstream, but we don't want to penalise our downstream. |
| 912 | // |
| 913 | // But at the same time, we want to ensure we have *some* buffer to send, so we aim |
| 914 | // to have at least min batch xmit bytes. |
| 915 | let buf_len = self.as_mut().project().buffer.len(); |
| 916 | // if buf_len >= BUFFER_MIN_BATCH_XMIT { |
| 917 | if buf_len >= BUFFER_MIN_XMIT { |
| 918 | /* |
| 919 | let excess = buf_len % BUFFER_MIN_XMIT; |
| 920 | let to_send = buf_len - excess; |
nothing calls this directly
no outgoing calls
no test coverage detected