From e68bb8306f71c073814aac5d6ec9026919d46378 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Thu, 2 May 2019 16:06:18 +0300
Subject: [PATCH] Add WSAStartup to universe.cpp to fix windows race condition

---
 net/cpp/src/listener.cpp | 1 +
 net/cpp/src/universe.cpp | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/net/cpp/src/listener.cpp b/net/cpp/src/listener.cpp
index 6e76aa20e..3b1c4af0e 100644
--- a/net/cpp/src/listener.cpp
+++ b/net/cpp/src/listener.cpp
@@ -36,6 +36,7 @@ int tcpListen(URI &uri) {
 	WSAData wsaData;
 	//If Win32 then load winsock
 	if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) {
+		LOG(ERROR) << "Could not initiate sockets";
 		return INVALID_SOCKET;
 	}
 	#endif
diff --git a/net/cpp/src/universe.cpp b/net/cpp/src/universe.cpp
index 6fe2891c1..066e7514d 100644
--- a/net/cpp/src/universe.cpp
+++ b/net/cpp/src/universe.cpp
@@ -187,6 +187,15 @@ void Universe::__start(Universe * u) {
 void Universe::_run() {
 	timeval block;
 
+#ifdef WIN32
+	WSAData wsaData;
+	//If Win32 then load winsock
+	if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
+		LOG(ERROR) << "Could not initiate sockets";
+		return;
+	}
+#endif
+
 	while (active_) {
 		int n = _setDescriptors();
 		int selres = 1;
-- 
GitLab