-
Notifications
You must be signed in to change notification settings - Fork 340
what should we do in async with ownership with tcpstream? #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@aohan237 Thanks for opening this issue. The way we're going to resolve this is by implementing Because of interior mutability we don't need a mutable reference, but instead a normal reference is good enough. Which sidesteps a lot of issues. Prior discussion on this can also be found here: #365. Because we already have two open issues about it, and a solution in the works, I'm going to go ahead and close this issue as "duplicate". Thanks heaps for filing; we hope we'll have a solution out soon! |
@yoshuawuyts |
@aohan237 If we implement async fn process(mut stream: TcpStream) -> io::Result<()> {
let mut dest = stream.clone();
io::copy(&mut stream, &mut dest).await?;
Ok(())
} |
@stjepang sorry for my slow understandings. io::copy seems that only copy steam content to dest, what's the different of simply copying the content? and here is the scene: what if we have a task continously reads the stream, and multi task which can simutanously write different commands to the stream? if implement clone for tcpstream, the writer seems mutex? still if we need to write then we need a mut borrow? i cant figure out how this works. is there any some docs can refer to ? thanks in advance |
|
you make it very clear. many thanks.
this make sense why but why cant we make use of the Arc? the Read/Write traits require only a mut borrow |
@aohan237 async fn process(stream: Arc<TcpStream>) -> io::Result<()> {
let dest = stream.clone();
io::copy(&mut &*stream, &mut &*dest).await?;
Ok(())
} |
@stjepang sorry for my late response. |
what should we do in async with ownership if something like spawn task which uses tcpstreams, which requires a mut borrow of the stream if you want to read or write
The text was updated successfully, but these errors were encountered: