|
@@ -202,7 +202,16 @@ bool SKlient::sende(const char* nachricht, int len) // sendet zum Klient
|
|
#else
|
|
#else
|
|
int l = (int)send(sock, nachricht + ll, len, MSG_NOSIGNAL);
|
|
int l = (int)send(sock, nachricht + ll, len, MSG_NOSIGNAL);
|
|
#endif
|
|
#endif
|
|
- if (l <= 0) return 0; // Fehler
|
|
|
|
|
|
+ if (l <= 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "send: " << l << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
|
|
+ return 0; // Fehler
|
|
|
|
+ }
|
|
len -= l;
|
|
len -= l;
|
|
ll += l;
|
|
ll += l;
|
|
}
|
|
}
|
|
@@ -218,7 +227,16 @@ bool SKlient::getNachricht(
|
|
while (len > 0)
|
|
while (len > 0)
|
|
{
|
|
{
|
|
int l = (int)recv(sock, nachricht + ll, len, MSG_WAITALL);
|
|
int l = (int)recv(sock, nachricht + ll, len, MSG_WAITALL);
|
|
- if (l <= 0) return 0; // Fehler
|
|
|
|
|
|
+ if (l <= 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "recv: " << l << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
|
|
+ return 0; // Fehler
|
|
|
|
+ }
|
|
len -= l;
|
|
len -= l;
|
|
ll += l;
|
|
ll += l;
|
|
}
|
|
}
|
|
@@ -242,6 +260,12 @@ bool SKlient::sendeEncrypted(
|
|
#endif
|
|
#endif
|
|
if (l <= 0)
|
|
if (l <= 0)
|
|
{
|
|
{
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "send: " << l << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
n->release();
|
|
n->release();
|
|
return 0; // Fehler
|
|
return 0; // Fehler
|
|
}
|
|
}
|
|
@@ -261,7 +285,16 @@ bool SKlient::getNachrichtEncrypted(
|
|
while (len > 0)
|
|
while (len > 0)
|
|
{
|
|
{
|
|
int l = (int)recv(sock, nachricht + ll, len, MSG_WAITALL);
|
|
int l = (int)recv(sock, nachricht + ll, len, MSG_WAITALL);
|
|
- if (l <= 0) return 0; // Fehler
|
|
|
|
|
|
+ if (l <= 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "recv: " << l << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
|
|
+ return 0; // Fehler
|
|
|
|
+ }
|
|
len -= l;
|
|
len -= l;
|
|
ll += l;
|
|
ll += l;
|
|
}
|
|
}
|
|
@@ -305,7 +338,17 @@ bool SKlient::hatNachricht(
|
|
FD_ZERO(&set);
|
|
FD_ZERO(&set);
|
|
FD_SET(sock, &set);
|
|
FD_SET(sock, &set);
|
|
timeval time = {zeit / 1000, zeit};
|
|
timeval time = {zeit / 1000, zeit};
|
|
- return select(0, &set, 0, 0, &time) == 1;
|
|
|
|
|
|
+ int result = select(0, &set, 0, 0, &time);
|
|
|
|
+ if (result < 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "select: " << result << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
|
|
+ }
|
|
|
|
+ return result > 0;
|
|
}
|
|
}
|
|
|
|
|
|
unsigned short SKlient::getPort() const // gibt den Port zurück
|
|
unsigned short SKlient::getPort() const // gibt den Port zurück
|
|
@@ -365,12 +408,34 @@ bool SKlient::waitForNextMessage()
|
|
timeout.tv_sec = 10;
|
|
timeout.tv_sec = 10;
|
|
timeout.tv_usec = 0;
|
|
timeout.tv_usec = 0;
|
|
rv = select((int)sock + 1, &set, NULL, NULL, &timeout);
|
|
rv = select((int)sock + 1, &set, NULL, NULL, &timeout);
|
|
- if (rv == -1) return 0;
|
|
|
|
|
|
+ if (rv == -1)
|
|
|
|
+ {
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "select: " << rv << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (!sock) return 0;
|
|
if (!sock) return 0;
|
|
char c;
|
|
char c;
|
|
|
|
+#ifdef WIN32
|
|
|
|
+ int l = (int)recv(sock, &c, 1, MSG_PEEK);
|
|
|
|
+#else
|
|
int l = (int)recv(sock, &c, 1, MSG_WAITALL | MSG_PEEK);
|
|
int l = (int)recv(sock, &c, 1, MSG_WAITALL | MSG_PEEK);
|
|
- if (l <= 0) return 0; // Fehler
|
|
|
|
|
|
+#endif
|
|
|
|
+ if (l <= 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef WIN32
|
|
|
|
+# ifdef _DEBUG
|
|
|
|
+ std::cout << "recv: " << l << " Error: " << WSAGetLastError()
|
|
|
|
+ << std::endl;
|
|
|
|
+# endif
|
|
|
|
+#endif
|
|
|
|
+ return 0; // Fehler
|
|
|
|
+ }
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -593,7 +658,14 @@ bool SSLSKlient::sende(const char* nachricht, int len) // sendet zum Klient
|
|
while (len > 0)
|
|
while (len > 0)
|
|
{
|
|
{
|
|
int l = SSL_write(ssl, nachricht + ll, len);
|
|
int l = SSL_write(ssl, nachricht + ll, len);
|
|
- if (l <= 0) return 0; // Fehler
|
|
|
|
|
|
+ if (l <= 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef _DEBUG
|
|
|
|
+ std::cout << "SSL_write: " << l
|
|
|
|
+ << " Error: " << SSL_get_error(ssl, l) << std::endl;
|
|
|
|
+#endif
|
|
|
|
+ return 0; // Fehler
|
|
|
|
+ }
|
|
len -= l;
|
|
len -= l;
|
|
ll += l;
|
|
ll += l;
|
|
}
|
|
}
|
|
@@ -609,7 +681,15 @@ bool SSLSKlient::getNachricht(
|
|
while (len > 0)
|
|
while (len > 0)
|
|
{
|
|
{
|
|
int l = (int)SSL_read(ssl, nachricht + ll, len);
|
|
int l = (int)SSL_read(ssl, nachricht + ll, len);
|
|
- if (l <= 0) return 0; // Fehler
|
|
|
|
|
|
+ if (l <= 0)
|
|
|
|
+ {
|
|
|
|
+#ifdef _DEBUG
|
|
|
|
+ SSL_ERROR_WANT_ASYNC
|
|
|
|
+ std::cout << "SSL_read: " << l
|
|
|
|
+ << " Error: " << SSL_get_error(ssl, l) << std::endl;
|
|
|
|
+#endif
|
|
|
|
+ return 0; // Fehler
|
|
|
|
+ }
|
|
len -= l;
|
|
len -= l;
|
|
ll += l;
|
|
ll += l;
|
|
}
|
|
}
|