Skip to content

Commit

Permalink
[git-packetline] Use what's learned previously to make it compile wit…
Browse files Browse the repository at this point in the history
…hout added buffer
  • Loading branch information
Byron committed May 18, 2021
1 parent 3866517 commit 88511f7
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions git-packetline/src/read/sidebands/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,50 +120,53 @@ where
fn poll_fill_buf(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<std::io::Result<&[u8]>> {
use futures_lite::FutureExt;
use std::io;
let this = self.as_mut().get_mut();
if this.pos >= this.cap {
let (ofs, cap) = loop {
// todo!("poll a future based on a field of ourselves - self-ref once again");
this.read_line = Some(this.parent.take().unwrap().read_line().boxed());
let line = match ready!(this.read_line.as_mut().expect("set above").poll(_cx)) {
Some(line) => line?.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
None => break (0, 0),
};
match this.handle_progress.as_mut() {
Some(handle_progress) => {
let band = line
.decode_band()
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
const ENCODED_BAND: usize = 1;
match band {
Band::Data(d) => break (U16_HEX_BYTES + ENCODED_BAND, d.len()),
Band::Progress(d) => {
let text = Text::from(d).0;
handle_progress(false, text);
}
Band::Error(d) => {
let text = Text::from(d).0;
handle_progress(true, text);
}
};
}
None => {
break match line.as_slice() {
Some(d) => (U16_HEX_BYTES, d.len()),
None => {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"encountered non-data line in a data-line only context",
)))
{
let this = self.as_mut().get_mut();
if this.pos >= this.cap {
let (ofs, cap) = loop {
// todo!("poll a future based on a field of ourselves - self-ref once again");
this.read_line = Some(this.parent.take().unwrap().read_line().boxed());
let line = match ready!(this.read_line.as_mut().expect("set above").poll(_cx)) {
Some(line) => line?.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
None => break (0, 0),
};
match this.handle_progress.as_mut() {
Some(handle_progress) => {
let band = line
.decode_band()
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
const ENCODED_BAND: usize = 1;
match band {
Band::Data(d) => break (U16_HEX_BYTES + ENCODED_BAND, d.len()),
Band::Progress(d) => {
let text = Text::from(d).0;
handle_progress(false, text);
}
Band::Error(d) => {
let text = Text::from(d).0;
handle_progress(true, text);
}
};
}
None => {
break match line.as_slice() {
Some(d) => (U16_HEX_BYTES, d.len()),
None => {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"encountered non-data line in a data-line only context",
)))
}
}
}
}
}
};
this.cap = cap + ofs;
this.pos = ofs;
};
this.cap = cap + ofs;
this.pos = ofs;
}
}
Poll::Ready(Ok(&this.parent.as_ref().unwrap().buf[this.pos..this.cap]))
let range = self.pos..self.cap;
Poll::Ready(Ok(&self.get_mut().parent.as_ref().unwrap().buf[range]))
}

fn consume(self: Pin<&mut Self>, amt: usize) {
Expand Down

0 comments on commit 88511f7

Please sign in to comment.