20 lines
696 B
Markdown
20 lines
696 B
Markdown
|
|
# TCP Sprint
|
||
|
|
|
||
|
|
This script demonstrates the risk of interleaving writes when cloning
|
||
|
|
`TcpStream` handles across threads, re:
|
||
|
|
[this discussion in the Servo Zulip](https://servo.zulipchat.com/#narrow/channel/263398-general/topic/TcpStream.3A.3Atry_clone.28.29.20thread.20safety.20in.20devtools/with/578172763).
|
||
|
|
|
||
|
|
It works by spawning 3 threads: 2 TCP clients, each of which sends predictable
|
||
|
|
chunks of bytes over a shared connection with `TcpStream::write_all()`, and 1
|
||
|
|
TCP listener, which tests whether messages arrive contiguously or scrambled
|
||
|
|
together.
|
||
|
|
|
||
|
|
Messages consist of the range `0x00..=0xff`, repeated to fill the desired
|
||
|
|
message size.
|
||
|
|
|
||
|
|
## Usage
|
||
|
|
|
||
|
|
```sh
|
||
|
|
cargo run <message size in bytes>
|
||
|
|
```
|