-
Notifications
You must be signed in to change notification settings - Fork 831
Refactor serve_tcp
code
#1042
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
Refactor serve_tcp
code
#1042
Conversation
7ccfa7f
to
03ccc6d
Compare
In this unit test we want to write all the pieces, use `write_all`. Clears clippy warning about not using return value of `write`.
We only simulate a single connection in the test function `serve_tcp`. Remove the unused loop (includes an unconditional break after first iteration) and use `next` directly. Found by clippy. Refactor only, no logic changes.
In test functions; we bind to `istream` only to re-bind immediately to `stream`, this is unnecessary and adds no additional information to the code.
03ccc6d
to
abfeb32
Compare
271d0ba Allow many arguments in test function (Tobin C. Harding) c0c88fe Use vec instead of pushing to a mutable vector (Tobin C. Harding) 73066e7 Use values() to iterate map values (Tobin C. Harding) 38ff025 Remove useless use of vec! (Tobin C. Harding) d8e82d5 Remove length comparison to zero (Tobin C. Harding) c1f34f5 Return Address directly (Tobin C. Harding) ff8d585 Use flat_map instead of map().flatten() (Tobin C. Harding) b24a112 Remove calls to clone from types that implement Copy (Tobin C. Harding) 2b8d93e Remove unnecessary explicit reference (Tobin C. Harding) ef90e3d Use plus-equals operator (Tobin C. Harding) 922b820 Replace assert!(false) with panic! (Tobin C. Harding) a8039e1 Remove redundant clone (Tobin C. Harding) cf8de73 Remove unnecessary cast of integer literal (Tobin C. Harding) 999ac45 Do not use assert_eq with literal bool (Tobin C. Harding) 827fcd8 Allow unusual digit grouping (Tobin C. Harding) 242c640 Remove redundant field names (Tobin C. Harding) 0f8f4c5 Collapse if statements (Tobin C. Harding) 229fcb9 Use if let instead of destructuring pattern (Tobin C. Harding) Pull request description: Clear all the clippy warnings (excl. #1042) that are returned by running `cargo clippy --all-targets`. I apologize in advance for the review burden :) ACKs for top commit: elichai: ACK 271d0ba apoelstra: ACK 271d0ba Tree-SHA512: 71ad2ec3db808e795791b7513f8b2a1c13dc90317f5328602c9ecbc31c09f82471f79c9c31a71a0ded5280554d1019d2bb4899fb9e8fa6421d46a2397cd31242
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK abfeb32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK abfeb32
Don't want to block a clear improvement but accept
would be cool. :)
ostream.shutdown(Shutdown::Both).unwrap(); | ||
break; | ||
// We only simulate a single connection. | ||
let mut ostream = listener.incoming().next().unwrap().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think let mut (ostream, _) = listener.accept().unwrap();
would be simpler and easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is better. Since we have multiple acks already I'll do it as a follow up PR. Cheers.
// We only simulate a single connection. | ||
let mut ostream = listener.incoming().next().unwrap().unwrap(); | ||
for piece in pieces { | ||
ostream.write_all(&piece[..]).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job spotting write_all
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy did that :)
During test network simulation we only accept a single connection, we can simplify the code by using `accept`. Done as a follow up to review suggestion: rust-bitcoin#1042 (comment)
b1faf63 Use listener.accept() (Tobin C. Harding) Pull request description: During test network simulation we only accept a single connection, we can simplify the code by using `accept`. Done as a follow up to review suggestion: #1042 (comment) ACKs for top commit: Kixunil: ACK b1faf63 apoelstra: ACK b1faf63 Tree-SHA512: b2ead15d3108db3e01d9faab5e3521403dad6a0f4c3cf505f88fefd020110c520a89b9406484c10b04c9a34073c8abc465941577b17b5a193b54502c23b14c61
abfeb32 Remove unnecessary local variable (Tobin C. Harding) 04b09a4 Remove unused loop (Tobin C. Harding) 380e001 Use write_all instead of write (Tobin C. Harding) Pull request description: Done while clearing clippy warnings, done as a separate PR because its not a simple glance to review like the others. Remove 2 clippy warnings and remove unnecessary local variable. ACKs for top commit: apoelstra: ACK abfeb32 Kixunil: ACK abfeb32 Tree-SHA512: 965708999c067dd8c156bbc54b711f608d524fab7051a0e56066f53b5c8d7bea1c233f04e77873b2624cd22e26a58f1d22f47870d2afe4347aa85335c3142245
During test network simulation we only accept a single connection, we can simplify the code by using `accept`. Done as a follow up to review suggestion: rust-bitcoin/rust-bitcoin#1042 (comment)
b1faf63 Use listener.accept() (Tobin C. Harding) Pull request description: During test network simulation we only accept a single connection, we can simplify the code by using `accept`. Done as a follow up to review suggestion: rust-bitcoin/rust-bitcoin#1042 (comment) ACKs for top commit: Kixunil: ACK b1faf63 apoelstra: ACK b1faf63 Tree-SHA512: b2ead15d3108db3e01d9faab5e3521403dad6a0f4c3cf505f88fefd020110c520a89b9406484c10b04c9a34073c8abc465941577b17b5a193b54502c23b14c61
Done while clearing clippy warnings, done as a separate PR because its not a simple glance to review like the others.
Remove 2 clippy warnings and remove unnecessary local variable.