summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-09-13 16:33:06 +0200
committerGitHub <noreply@github.com>2018-09-13 16:33:06 +0200
commit4d228e66b45a6a3859decde6b2452c78728f8958 (patch)
tree9ca9e38fa99746af273479a6abd9e48d76fdb914 /drivers
parent68f224a50483c39c6d13141c0ceb26549ad2579f (diff)
parent01c3c1a07bfbaf6df8b1154e5ef31ecc890b03a3 (diff)
Merge pull request #22030 from Faless/sockets_fixes
Properly initialize Winsock on startup
Diffstat (limited to 'drivers')
-rw-r--r--drivers/unix/net_socket_posix.cpp19
-rw-r--r--drivers/unix/net_socket_posix.h1
-rw-r--r--drivers/unix/os_unix.cpp2
3 files changed, 21 insertions, 1 deletions
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp
index ea19b6a700..9dcc6038ab 100644
--- a/drivers/unix/net_socket_posix.cpp
+++ b/drivers/unix/net_socket_posix.cpp
@@ -150,9 +150,24 @@ NetSocket *NetSocketPosix::_create_func() {
}
void NetSocketPosix::make_default() {
+#if defined(WINDOWS_ENABLED)
+ if (_create == NULL) {
+ WSADATA data;
+ WSAStartup(MAKEWORD(2, 2), &data);
+ }
+#endif
_create = _create_func;
}
+void NetSocketPosix::cleanup() {
+#if defined(WINDOWS_ENABLED)
+ if (_create != NULL) {
+ WSACleanup();
+ }
+ _create = NULL;
+#endif
+}
+
NetSocketPosix::NetSocketPosix() {
_sock = SOCK_EMPTY;
_ip_type = IP::TYPE_NONE;
@@ -169,10 +184,11 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() {
if (err == WSAEISCONN)
return ERR_NET_IS_CONNECTED;
- if (err == WSAEINPROGRESS || errno == WSAEALREADY)
+ if (err == WSAEINPROGRESS || err == WSAEALREADY)
return ERR_NET_IN_PROGRESS;
if (err == WSAEWOULDBLOCK)
return ERR_NET_WOULD_BLOCK;
+ ERR_PRINTS("Socket error: " + itos(err));
return ERR_NET_OTHER;
#else
if (errno == EISCONN)
@@ -181,6 +197,7 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() {
return ERR_NET_IN_PROGRESS;
if (errno == EAGAIN || errno == EWOULDBLOCK)
return ERR_NET_WOULD_BLOCK;
+ ERR_PRINTS("Socket error: " + itos(errno));
return ERR_NET_OTHER;
#endif
}
diff --git a/drivers/unix/net_socket_posix.h b/drivers/unix/net_socket_posix.h
index ee178136f3..8177e01987 100644
--- a/drivers/unix/net_socket_posix.h
+++ b/drivers/unix/net_socket_posix.h
@@ -67,6 +67,7 @@ protected:
public:
static void make_default();
+ static void cleanup();
virtual Error open(Type p_sock_type, IP::Type &ip_type);
virtual void close();
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 1225d00aad..9936c95cf9 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -139,6 +139,8 @@ void OS_Unix::initialize_core() {
}
void OS_Unix::finalize_core() {
+
+ NetSocketPosix::cleanup();
}
void OS_Unix::alert(const String &p_alert, const String &p_title) {