Created
November 22, 2019 17:01
-
-
Save jeromegn/c56f42ef53d0bc80f679c4506d270e2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fn transfer(inbound: MeteredIO, outbound: MeteredIO) -> Result<(), Error> | |
{ | |
let (mut ri, mut wi) = tokio::io::split(inbound); | |
let (mut ro, mut wo) = tokio::io::split(outbound); | |
let mut client_to_server = ri.copy(&mut wo).fuse(); | |
let mut server_to_client = ro.copy(&mut wi).fuse(); | |
loop { | |
futures::select! { | |
n = client_to_server => { | |
match n { | |
Ok(n) => log::warn!("copied {} from client-to-server", n), | |
Err(e) => log::error!("error copying from client-to-server: {}", e), | |
}; | |
drop(client_to_server); | |
match wo.shutdown().await { | |
Ok(_) => (), | |
Err(e) => log::error!("error shutting down client-to-server stream: {}", e), | |
}; | |
}, | |
n = server_to_client => { | |
match n { | |
Ok(n) => log::warn!("copied {} from server-to-client", n), | |
Err(e) => log::error!("error copying from server-to-client: {}", e), | |
}; | |
match wi.shutdown().await { | |
Ok(_) => (), | |
Err(e) => log::error!("error shutting down server-to-client stream: {}", e), | |
}; | |
}, | |
complete => { | |
log::warn!("done copying!"); | |
break | |
}, | |
// default => break | |
} | |
} | |
Ok(()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error[E0499]: cannot borrow `wo` as mutable more than once at a time | |
--> src/handlers/mod.rs:106:23 | |
| | |
96 | let mut client_to_server = ri.copy(&mut wo).fuse(); | |
| ------- first mutable borrow occurs here | |
... | |
101 | n = client_to_server => { | |
| ---------------- first borrow later captured here by closure | |
... | |
106 | match wo.shutdown().await { | |
| ^^ second mutable borrow occurs here | |
error[E0499]: cannot borrow `wi` as mutable more than once at a time | |
--> src/handlers/mod.rs:116:23 | |
| | |
97 | let mut server_to_client = ro.copy(&mut wi).fuse(); | |
| ------- first mutable borrow occurs here | |
... | |
111 | n = server_to_client => { | |
| ---------------- first borrow later captured here by closure | |
... | |
116 | match wi.shutdown().await { | |
| ^^ second mutable borrow occurs here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment