Skip to content

Commit 9a51d28

Browse files
committed
only initializing wsa startup for the first invocation
1 parent 05c2adc commit 9a51d28

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/dds.net-connector-cpp.lib/connector/src/internal/src/network_client.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ using namespace dds::net::connector;
1616
using namespace dds::net::connector::_internal;
1717

1818

19+
20+
#if TARGET_PLATFORM == PLATFORM_WINDOWS
21+
22+
static int wsaStartCount = 0;
23+
24+
#endif
25+
26+
27+
1928
dds::net::connector::_internal::
2029
NetworkClient::NetworkClient(
2130
Logger* logger,
@@ -50,18 +59,27 @@ dds::net::connector::_internal::
5059

5160
memset(&this->targetSocketAddress, 0, sizeof(this->targetSocketAddress));
5261

62+
63+
5364
#if TARGET_PLATFORM == PLATFORM_WINDOWS
5465

66+
if (wsaStartCount == 0)
67+
{
5568
WSADATA wsaData;
69+
5670
int windowsStartupResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
71+
5772
if (windowsStartupResult != 0)
5873
{
59-
std::string msg = "WSAStartup failed with return code: ";
74+
std::string msg = "WSAStartup failed with error code: ";
6075
msg += windowsStartupResult;
6176

6277
this->logger->error(msg.c_str());
6378
return;
6479
}
80+
}
81+
82+
wsaStartCount++;
6583

6684
#endif
6785
}

0 commit comments

Comments
 (0)