Skip to content

Commit ff1c741

Browse files
committed
Refactor: Tight up unix::Client::new impl
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
1 parent 0345ff6 commit ff1c741

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/unix.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ impl Client {
3535
// 128 cores.
3636
const BUFFER: [u8; 128] = [b'|'; 128];
3737

38-
while limit >= BUFFER.len() {
39-
(&client.write).write_all(&BUFFER)?;
40-
limit -= BUFFER.len();
41-
}
38+
while limit > 0 {
39+
let n = limit.min(BUFFER.len());
4240

43-
if limit > 0 {
44-
(&client.write).write_all(&BUFFER[..limit])?;
41+
(&client.write).write_all(&BUFFER[..n])?;
42+
limit -= n;
4543
}
4644

4745
Ok(client)

0 commit comments

Comments
 (0)