Skip to content

Write to a TcpStream while waiting for it to become writable from another task/thread #5453

Answered by Darksonn
OverShifted asked this question in Q&A
Discussion options

You must be logged in to vote

Wrapping an IO resource in a mutex or rwlock is almost wrong. You are deadlocking because the reader and the writer are blocking each other. You should split your IO resource instead. For the specific case of TcpStream, you can use the TcpStream::into_split method to get a read and write half that can be used independently.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@OverShifted
Comment options

Answer selected by OverShifted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants