Просмотр исходного кода

fix waitForNextMessage not returning when socet connection was closed

Kolja Strohm 1 год назад
Родитель
Сommit
e582a37a29
2 измененных файлов с 26 добавлено и 0 удалено
  1. 13 0
      Network/Klient.cpp
  2. 13 0
      Network/Server.cpp

+ 13 - 0
Network/Klient.cpp

@@ -222,6 +222,19 @@ const char* Klient::getServerIp() const // gibt die Ip zur
 
 bool Klient::waitForNextMessage() const // wartet bis es etwas zu empfangen gibt
 {
+    fd_set set;
+    int rv = 0;
+    struct timeval timeout;
+    while (rv == 0 && sock)
+    {
+        FD_ZERO(&set);      /* clear the set */
+        FD_SET(sock, &set); /* add our file descriptor to the set */
+        timeout.tv_sec = 10;
+        timeout.tv_usec = 0;
+        rv = select((int)sock + 1, &set, NULL, NULL, &timeout);
+        if (rv == -1) return 0;
+    }
+    if (!sock) return 0;
 	char c;
 	int l = (int)recv(sock, &c, 1, MSG_WAITALL | MSG_PEEK);
 	if (l <= 0)

+ 13 - 0
Network/Server.cpp

@@ -342,6 +342,19 @@ bool SSLErrorCheck(__int64 result, const char* action)
 
 bool SKlient::waitForNextMessage() const // wartet bis es etwas zu empfangen gibt
 {
+    fd_set set;
+    int rv = 0;
+    struct timeval timeout;
+    while (rv == 0 && sock)
+    {
+        FD_ZERO(&set);      /* clear the set */
+        FD_SET(sock, &set); /* add our file descriptor to the set */
+        timeout.tv_sec = 10;
+        timeout.tv_usec = 0;
+        rv = select((int)sock + 1, &set, NULL, NULL, &timeout);
+        if (rv == -1) return 0;
+    }
+    if (!sock) return 0;
 	char c;
 	int l = (int)recv(sock, &c, 1, MSG_WAITALL | MSG_PEEK);
 	if (l <= 0)