Merge bitcoin/bitcoin#21659: net: flag relevant Sock methods with [[nodiscard]]

e286cd0d7b net: flag relevant Sock methods with [[nodiscard]] (Vasil Dimov)

Pull request description:

  Flag relevant Sock methods with `[[nodiscard]]` to avoid issues like the one fixed in https://github.com/bitcoin/bitcoin/pull/21631.

ACKs for top commit:
  practicalswift:
    cr ACK e286cd0d7b: the only changes made are additions of `[[nodiscard]]` and `(void)` where appropriate
  laanwj:
    Code review ACK e286cd0d7b

Tree-SHA512: addc361968d24912bb625b42f4db557791556bf0ffad818252a89a32d76ac22758ec70f8282dcfbfd77eebec20a8e6bb7557c8ed08d50a58de95378c34955973
This commit is contained in:
W. J. van der Laan
2021-05-19 14:46:10 +02:00
4 changed files with 21 additions and 18 deletions

View File

@@ -37,7 +37,7 @@ FUZZ_TARGET_INIT(i2p, initialize_i2p)
if (sess.Listen(conn)) {
if (sess.Accept(conn)) {
try {
conn.sock->RecvUntilTerminator('\n', 10ms, interrupt, i2p::sam::MAX_MSG_SIZE);
(void)conn.sock->RecvUntilTerminator('\n', 10ms, interrupt, i2p::sam::MAX_MSG_SIZE);
} catch (const std::runtime_error&) {
}
}

View File

@@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(wait)
Sock sock0(s[0]);
Sock sock1(s[1]);
std::thread waiter([&sock0]() { sock0.Wait(24h, Sock::RECV); });
std::thread waiter([&sock0]() { (void)sock0.Wait(24h, Sock::RECV); });
BOOST_REQUIRE_EQUAL(sock1.Send("a", 1, 0), 1);
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(recv_until_terminator_limit)
// BOOST_CHECK_EXCEPTION() writes to some variables shared with the main thread which
// creates a data race. So mimic it manually.
try {
sock_recv.RecvUntilTerminator('\n', timeout, interrupt, max_data);
(void)sock_recv.RecvUntilTerminator('\n', timeout, interrupt, max_data);
} catch (const std::runtime_error& e) {
threw_as_expected = HasReason("too many bytes without a terminator")(e);
}