Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 29, 2023
1 parent 70433e0 commit 8024ded
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions ntex-glommio/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,16 @@ impl Future for WriteTask {
// use disconnect timeout, otherwise it could hang forever.
loop {
match st {
Shutdown::None(ref mut fut) => {
Shutdown::Flush => {
// flush write buffer
let mut io = this.io.0.borrow_mut();
match this.state.with_buf(|buf| flush_io(&mut *io, buf, cx)) {
Poll::Ready(Ok(())) => {
let io = this.io.clone();
let fut = Box::pin(async move {
io.0.borrow().shutdown(std::net::Shutdown::Write).await
io.0.borrow()

Check warning on line 206 in ntex-glommio/src/io.rs

View workflow job for this annotation

GitHub Actions / clippy

this `RefCell` reference is held across an `await` point

warning: this `RefCell` reference is held across an `await` point --> ntex-glommio/src/io.rs:206:41 | 206 | ... io.0.borrow() | ^^^^^^^^^^^^^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through --> ntex-glommio/src/io.rs:205:67 | 205 | ... let fut = Box::pin(async move { | _____________________________________________________^ 206 | | ... io.0.borrow() 207 | | ... .shutdown(std::net::Shutdown::Write) 208 | | ... .await 209 | | ... }); | |_______________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref = note: `#[warn(clippy::await_holding_refcell_ref)]` on by default
.shutdown(std::net::Shutdown::Write)
.await
});
*st = Shutdown::Close(fut);
continue;
Expand Down Expand Up @@ -484,11 +486,7 @@ impl Future for UnixWriteTask {
sleep(time)
};

let io = this.io.clone();
let fut = Box::pin(async move {
io.0.borrow().shutdown(std::net::Shutdown::Write).await
});
this.st = IoWriteState::Shutdown(timeout, Shutdown::None(fut));
this.st = IoWriteState::Shutdown(timeout, Shutdown::Flush);
self.poll(cx)
}
Poll::Ready(WriteStatus::Terminate) => {
Expand All @@ -506,16 +504,18 @@ impl Future for UnixWriteTask {
// use disconnect timeout, otherwise it could hang forever.
loop {
match st {
Shutdown::None(ref mut fut) => {
Shutdown::Flush => {
// flush write buffer
let mut io = this.io.0.borrow_mut();
match this.state.with_buf(|buf| flush_io(&mut *io, buf, cx)) {
Poll::Ready(Ok(())) => {
if ready!(fut.poll(cx)).is_err() {
this.state.close(None);
return Poll::Ready(());
}
*st = Shutdown::Stopping(0);
let io = this.io.clone();
let fut = Box::pin(async move {
io.0.borrow()

Check warning on line 514 in ntex-glommio/src/io.rs

View workflow job for this annotation

GitHub Actions / clippy

this `RefCell` reference is held across an `await` point

warning: this `RefCell` reference is held across an `await` point --> ntex-glommio/src/io.rs:514:41 | 514 | ... io.0.borrow() | ^^^^^^^^^^^^^ | = help: ensure the reference is dropped before calling `await` note: these are all the `await` points this reference is held through --> ntex-glommio/src/io.rs:513:67 | 513 | ... let fut = Box::pin(async move { | _____________________________________________________^ 514 | | ... io.0.borrow() 515 | | ... .shutdown(std::net::Shutdown::Write) 516 | | ... .await 517 | | ... }); | |_______________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref
.shutdown(std::net::Shutdown::Write)
.await
});
*st = Shutdown::Close(fut);
continue;
}
Poll::Ready(Err(err)) => {
Expand All @@ -529,6 +529,14 @@ impl Future for UnixWriteTask {
Poll::Pending => (),
}
}
Shutdown::Close(ref mut fut) => {
if ready!(fut.poll(cx)).is_err() {
this.state.close(None);
return Poll::Ready(());
}
*st = Shutdown::Stopping(0);
continue;
}
Shutdown::Stopping(ref mut count) => {
// read until 0 or err
let mut buf = [0u8; 512];
Expand Down

0 comments on commit 8024ded

Please sign in to comment.