Merge rust-bitcoin/rust-bitcoin#1042: Refactor `serve_tcp` code

abfeb32e35 Remove unnecessary local variable (Tobin C. Harding)
04b09a4e8d Remove unused loop (Tobin C. Harding)
380e0016cc 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 abfeb32e35
  Kixunil:
    ACK abfeb32e35

Tree-SHA512: 965708999c067dd8c156bbc54b711f608d524fab7051a0e56066f53b5c8d7bea1c233f04e77873b2624cd22e26a58f1d22f47870d2afe4347aa85335c3142245
This commit is contained in:
Andrew Poelstra 2022-06-16 12:53:07 +00:00
commit e00b0c39ca
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 10 additions and 15 deletions

View File

@ -203,18 +203,15 @@ mod test {
// 2. Spawning thread that will be writing our messages to the TCP Stream at the server side
// in async mode
let handle = thread::spawn(move || {
for ostream in listener.incoming() {
let mut ostream = ostream.unwrap();
// We only simulate a single connection.
let mut ostream = listener.incoming().next().unwrap().unwrap();
for piece in pieces {
ostream.write(&piece[..]).unwrap();
ostream.write_all(&piece[..]).unwrap();
ostream.flush().unwrap();
thread::sleep(Duration::from_secs(1));
}
ostream.shutdown(Shutdown::Both).unwrap();
break;
}
});
// 3. Creating client side of the TCP socket connection
@ -228,11 +225,10 @@ mod test {
#[test]
fn read_multipartmsg_test() {
// Setting up TCP connection emulation
let (handle, istream) = serve_tcp(vec![
let (handle, stream) = serve_tcp(vec![
// single message split in two parts to emulate real network conditions
MSG_VERSION[..24].to_vec(), MSG_VERSION[24..].to_vec()
]);
let stream = istream;
let mut reader = StreamReader::new(stream, None);
// Reading and checking the whole message back
@ -246,13 +242,12 @@ mod test {
#[test]
fn read_sequencemsg_test() {
// Setting up TCP connection emulation
let (handle, istream) = serve_tcp(vec![
let (handle, stream) = serve_tcp(vec![
// Real-world Bitcoin core communication case for /Satoshi:0.17.1/
MSG_VERSION[..23].to_vec(), MSG_VERSION[23..].to_vec(),
MSG_VERACK.to_vec(),
MSG_ALERT[..24].to_vec(), MSG_ALERT[24..].to_vec()
]);
let stream = istream;
let mut reader = StreamReader::new(stream, None);
// Reading and checking the first message (Version)