diff options
author | fanquake <fanquake@gmail.com> | 2023-11-29 17:10:28 +0000 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-11-29 17:14:34 +0000 |
commit | dd73c229763927cddc56b19ef7b1a311ff952a60 (patch) | |
tree | 59f73426a1c67b15e22407096cf21723a5d51a74 /src/common/system.h | |
parent | d00d50e78ac97b7e0bbee7ff5446296e8af805b6 (diff) | |
parent | fd4c6a10f2285f16c5d0215eb56a3060441f3ef2 (diff) |
Merge bitcoin/bitcoin#28486: test, bench: Initialize and terminate use of Winsock properly
fd4c6a10f2285f16c5d0215eb56a3060441f3ef2 test: Setup networking globally (Hennadii Stepanov)
Pull request description:
On the master branch, when compiling without external signer support, the `bench_bitcoin.exe` does not initialize Winsock DLL that is required, for example, here: https://github.com/bitcoin/bitcoin/blob/459272d639b9547f68000d2b9a5a0d991d477de5/src/bench/addrman.cpp#L124
Moreover, Windows docs explicitly [state](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsacleanup) that `WSAStartup` and `WSACleanup` must be balanced:
> There must be a call to `WSACleanup` for each successful call to `WSAStartup`. Only the final `WSACleanup` function call performs the actual cleanup. The preceding calls simply decrement an internal reference count in the WS2_32.DLL.
That is not the case for our unit tests because the `SetupNetworking()` call is a part of the `BasicTestingSetup` fixture and is invoked multiple times, while `~CNetCleanup()` is invoked once only, at the end of the test binary execution.
This PR fixes Winsock DLL initialization and termination.
More docs:
- https://learn.microsoft.com/en-us/windows/win32/winsock/initializing-winsock
- https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartup
- https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsacleanup
Fix https://github.com/bitcoin/bitcoin/issues/28940.
ACKs for top commit:
maflcko:
lgtm ACK fd4c6a10f2285f16c5d0215eb56a3060441f3ef2
Tree-SHA512: d360eaf776943f7f7a35ed5a5f9f3228d9e3d18eb824e5997cdc8eadddf466abe9f2da4910ee3bb86bf5411061e758259f7e1ec344f234ef7996f1bf8781dcda
Diffstat (limited to 'src/common/system.h')
-rw-r--r-- | src/common/system.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/common/system.h b/src/common/system.h index e8018f9b10..83280d46ee 100644 --- a/src/common/system.h +++ b/src/common/system.h @@ -17,7 +17,7 @@ int64_t GetStartupTime(); void SetupEnvironment(); -bool SetupNetworking(); +[[nodiscard]] bool SetupNetworking(); #ifndef WIN32 std::string ShellEscape(const std::string& arg); #endif |