File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 18
18
19
19
#include < bsoncxx/v1/config/export.hpp>
20
20
21
+ #include < cstdlib>
22
+ #include < iostream>
21
23
#include < system_error>
22
24
25
+ #include < bsoncxx/private/bson.hh> // <winsock.h> via <bson/bson-compat.h>
26
+
23
27
#include < catch2/catch_session.hpp>
24
28
29
+ // Ensure the Winsock DLL is initialized prior to calling `gethostname` in `bsoncxx::oid::oid()`:
30
+ // - bson_oid_init -> bson_context_get_default -> ... -> _bson_context_init_random -> gethostname.
31
+ struct WSAGuard {
32
+ ~WSAGuard () {
33
+ #if defined(_WIN32)
34
+ (void )WSACleanup ();
35
+ #endif
36
+ }
37
+
38
+ WSAGuard (WSAGuard&&) = delete ;
39
+ WSAGuard& operator =(WSAGuard&) = delete ;
40
+ WSAGuard (WSAGuard const &) = delete ;
41
+ WSAGuard& operator =(WSAGuard const &) = delete ;
42
+
43
+ WSAGuard () {
44
+ #if defined(_WIN32)
45
+ WSADATA wsaData;
46
+ if (WSAStartup ((MAKEWORD (2 , 2 )), &wsaData) != 0 ) {
47
+ std::cerr << " WSAStartup failed: " << WSAGetLastError () << std::endl;
48
+ std::abort ();
49
+ }
50
+ #endif
51
+ }
52
+ };
53
+
25
54
int BSONCXX_ABI_CDECL main (int argc, char * argv[]) {
55
+ WSAGuard wsa_guard;
26
56
return Catch::Session ().run (argc, argv);
27
57
}
28
58
You can’t perform that action at this time.
0 commit comments