Sfoglia il codice sorgente

translate to english

Kolja Strohm 1 mese fa
parent
commit
d5a943baa3
3 ha cambiato i file con 46 aggiunte e 58 eliminazioni
  1. 23 32
      Network/Client.cpp
  2. 19 22
      Network/Server.cpp
  3. 4 4
      Network/WebSocket.cpp

+ 23 - 32
Network/Client.cpp

@@ -1,4 +1,4 @@
-#define INCLUDE_SSL
+#define INCLUDE_SSL
 #include "Client.h"
 
 #ifndef WIN32
@@ -6,7 +6,7 @@
 #    include <string.h>
 #    include <sys/select.h>
 #endif
-#include <Datei.h>
+#include <File.h>
 #include <Key.h>
 #include <Logging.h>
 
@@ -42,8 +42,7 @@ void Client::setSendKeyZ(Encryption::Key* key) // Sets the key for sending
     sendKey = key;
 }
 
-void Client::setReceiveKeyZ(
-    Encryption::Key* key) // Sets the key for receiving
+void Client::setReceiveKeyZ(Encryption::Key* key) // Sets the key for receiving
 {
     if (receiveKey) receiveKey->release();
     receiveKey = key;
@@ -62,8 +61,7 @@ void Client::setReceiveKey(
     receiveKey->setKey(key, len);
 }
 
-bool Client::connect(
-    unsigned short port, const char* ip) // connects to server
+bool Client::connect(unsigned short port, const char* ip) // connects to server
 {
     if (sendKey) sendKey->setPos(0);
     if (receiveKey) receiveKey->setPos(0);
@@ -78,7 +76,7 @@ bool Client::connect(
     }
     memcpy((char*)&server.sin_addr, &sIp, sizeof(sIp));
     server.sin_port = htons(port); // port
-    if (connect(sock, (struct sockaddr*)&server, sizeof(server))
+    if (::connect(sock, (struct sockaddr*)&server, sizeof(server))
         < 0) // connect
     {
         errorOccured = 1;
@@ -94,9 +92,9 @@ bool Client::send(const char* message, int len) // sends to server
     while (len > 0)
     {
 #ifdef WIN32
-        int l = send(sock, message + ll, len, 0);
+        int l = ::send(sock, message + ll, len, 0);
 #else
-        int l = (int)send(sock, message + ll, len, MSG_NOSIGNAL);
+        int l = (int)::send(sock, message + ll, len, MSG_NOSIGNAL);
 #endif
         if (l <= 0)
         {
@@ -144,15 +142,14 @@ bool Client::sendEncrypted(const char* message, int len) // sends to server
 {
     if (!sendKey) return send(message, len);
     Encryption::Bytes* n = new Encryption::Bytes(message, len);
-    sendKey->codieren(
-        dynamic_cast<Framework::Encryption::Bytes*>(n->getThis()));
+    sendKey->encode(dynamic_cast<Framework::Encryption::Bytes*>(n->getThis()));
     int ll = 0;
     while (len > 0)
     {
 #ifdef WIN32
-        int l = send(sock, n->getBytes() + ll, len, 0);
+        int l = ::send(sock, n->getBytes() + ll, len, 0);
 #else
-        int l = (int)send(sock, n->getBytes() + ll, len, MSG_NOSIGNAL);
+        int l = (int)::send(sock, n->getBytes() + ll, len, MSG_NOSIGNAL);
 #endif
         if (l <= 0)
         {
@@ -174,8 +171,7 @@ bool Client::sendEncrypted(const char* message, int len) // sends to server
     return 1;
 }
 
-bool Client::getMessageEncrypted(
-    char* message, int len) // receives message
+bool Client::getMessageEncrypted(char* message, int len) // receives message
 {
     if (!receiveKey) return getMessage(message, len);
     int ll = 0;
@@ -198,21 +194,19 @@ bool Client::getMessageEncrypted(
     }
     Encryption::Bytes* n = new Encryption::Bytes();
     n->setBytesZ(message, ll);
-    receiveKey->decodieren(n);
+    receiveKey->decode(n);
     downStreamBytes += ll;
     return 1;
 }
 
-int Client::getDownloadBytes(
-    bool reset) // returns the number of received bytes
+int Client::getDownloadBytes(bool reset) // returns the number of received bytes
 {
     int ret = downStreamBytes;
     if (reset) downStreamBytes = 0;
     return ret;
 }
 
-int Client::getUploadBytes(
-    bool reset) // returns the number of sent bytes
+int Client::getUploadBytes(bool reset) // returns the number of sent bytes
 {
     int ret = upStreamBytes;
     if (reset) upStreamBytes = 0;
@@ -234,12 +228,12 @@ bool Client::disconnect() // Disconnects from server
 }
 
 // constant
-bool Client::hasMessage(int time) // Waits for a message for a given time
+bool Client::hasMessage(int waitTime) // Waits for a message for a given time
 {
     fd_set set;
     FD_ZERO(&set);
     FD_SET(sock, &set);
-    timeval time = {time / 1000, time};
+    timeval time = {waitTime / 1000, waitTime};
     int result = select(0, &set, 0, 0, &time);
     if (result < 0)
     {
@@ -263,7 +257,8 @@ const char* Client::getServerIp() const // returns the IP
     return inet_ntoa(server.sin_addr);
 }
 
-bool Client::waitForNextMessage() const // waits until there is something to receive
+bool Client::waitForNextMessage()
+    const // waits until there is something to receive
 {
     fd_set set;
     int rv = 0;
@@ -306,8 +301,7 @@ bool Client::waitForNextMessage() const // waits until there is something to rec
     return 1;
 }
 
-bool Client::isConnected()
-    const // returns true if a connection exists
+bool Client::isConnected() const // returns true if a connection exists
 {
     return sock != 0 && !errorOccured;
 }
@@ -407,8 +401,7 @@ int SSLClient::getDownloadBytes(
     return ret;
 }
 
-int SSLClient::getUploadBytes(
-    bool reset) // returns the number of sent bytes
+int SSLClient::getUploadBytes(bool reset) // returns the number of sent bytes
 {
     int ret = upStreamBytes;
     if (reset) upStreamBytes = 0;
@@ -423,18 +416,16 @@ bool SSLClient::disconnect() // Disconnects from server
 }
 
 // constant
-bool SSLClient::hasMessage(
-    int time) // Waits for a message for a given time
+bool SSLClient::hasMessage(int waitTime) // Waits for a message for a given time
 {
     fd_set set;
     FD_ZERO(&set);
     FD_SET(SSL_get_rfd(ssl), &set);
-    timeval time = {time / 1000, time};
+    timeval time = {waitTime / 1000, waitTime};
     return SSL_pending(ssl) > 0 || select(0, &set, 0, 0, &time) == 1;
 }
 
-unsigned short
-SSLClient::getServerPort() const // returns the server port
+unsigned short SSLClient::getServerPort() const // returns the server port
 {
     return port;
 }

+ 19 - 22
Network/Server.cpp

@@ -34,7 +34,7 @@ Server::~Server()
 bool Server::connect(unsigned short port, int queueLength) // Opens the socket
 {
     sock = socket(AF_INET, SOCK_STREAM, 0); // Create socket
-    address.sin_port = htons(port);        // set port
+    address.sin_port = htons(port);         // set port
     if (sock < 0)
     {
         sock = 0;
@@ -87,8 +87,8 @@ SClient* Server::getClient() // accepts a client
         return 0;
     }
 #else
-    SOCKET cls = accept(
-        sock, (sockaddr*)&client, (socklen_t*)&len); // receive client
+    SOCKET cls
+        = accept(sock, (sockaddr*)&client, (socklen_t*)&len); // receive client
     if (!cls)
     {
         if (errno == ECONNABORTED || errno == EBADF) disconnect();
@@ -122,8 +122,7 @@ unsigned short Server::getPort() const // returns the port
     return htons(address.sin_port);
 }
 
-bool Server::isConnected()
-    const // returns 1 if the server is connected
+bool Server::isConnected() const // returns 1 if the server is connected
 {
     return sock != 0;
 }
@@ -171,8 +170,7 @@ void SClient::setSendKeyZ(Encryption::Key* key) // Sets the key for sending
     sendKey = key;
 }
 
-void SClient::setReceiveKeyZ(
-    Encryption::Key* key) // Sets the key for receiving
+void SClient::setReceiveKeyZ(Encryption::Key* key) // Sets the key for receiving
 {
     if (receiveKey) receiveKey->release();
     receiveKey = key;
@@ -198,9 +196,9 @@ bool SClient::send(const char* message, int len) // sends to client
     while (len > 0)
     {
 #ifdef WIN32
-        int l = send(sock, message + ll, len, 0);
+        int l = ::send(sock, message + ll, len, 0);
 #else
-        int l = (int)send(sock, message + ll, len, MSG_NOSIGNAL);
+        int l = (int)::send(sock, message + ll, len, MSG_NOSIGNAL);
 #endif
         if (l <= 0)
         {
@@ -247,14 +245,14 @@ bool SClient::sendEncrypted(const char* message, int len) // sends to server
 {
     if (!sendKey) return send(message, len);
     Encryption::Bytes* n = new Encryption::Bytes(message, len);
-    sendKey->codieren(dynamic_cast<Encryption::Bytes*>(n->getThis()));
+    sendKey->encode(dynamic_cast<Encryption::Bytes*>(n->getThis()));
     int ll = 0;
     while (len > 0)
     {
 #ifdef WIN32
-        int l = send(sock, n->getBytes() + ll, len, 0);
+        int l = ::send(sock, n->getBytes() + ll, len, 0);
 #else
-        int l = (int)send(sock, n->getBytes() + ll, len, MSG_NOSIGNAL);
+        int l = (int)::send(sock, n->getBytes() + ll, len, MSG_NOSIGNAL);
 #endif
         if (l <= 0)
         {
@@ -297,7 +295,7 @@ bool SClient::getMessageEncrypted(char* message, int len) // receives message
     }
     Encryption::Bytes* n = new Encryption::Bytes();
     n->setBytesZ(message, ll);
-    receiveKey->decodieren(n);
+    receiveKey->decode(n);
     downStreamBytes += ll;
     return 1;
 }
@@ -310,8 +308,7 @@ int SClient::getDownloadBytes(
     return ret;
 }
 
-int SClient::getUploadBytes(
-    bool reset) // returns the number of sent bytes
+int SClient::getUploadBytes(bool reset) // returns the number of sent bytes
 {
     int ret = upStreamBytes;
     if (reset) upStreamBytes = 0;
@@ -329,12 +326,12 @@ bool SClient::disconnect() // disconnects from client
 
 // constant
 bool SClient::hasMessage(
-    int time) const // Waits for a message for a given time
+    int waitTime) const // Waits for a message for a given time
 {
     fd_set set;
     FD_ZERO(&set);
     FD_SET(sock, &set);
-    timeval time = {time / 1000, time};
+    timeval time = {waitTime / 1000, waitTime};
     int result = select(0, &set, 0, 0, &time);
     if (result < 0)
     {
@@ -670,7 +667,8 @@ bool SSLSClient::send(const char* message, int len) // sends to client
     return 1;
 }
 
-bool SSLSClient::getMessage(char* message, int len) // receives message from client
+bool SSLSClient::getMessage(
+    char* message, int len) // receives message from client
 {
     if (!ssl) return 0;
     int ll = 0;
@@ -700,8 +698,7 @@ int SSLSClient::getDownloadBytes(
     return ret;
 }
 
-int SSLSClient::getUploadBytes(
-    bool reset) // returns the number of sent bytes
+int SSLSClient::getUploadBytes(bool reset) // returns the number of sent bytes
 {
     int ret = upStreamBytes;
     if (reset) upStreamBytes = 0;
@@ -721,12 +718,12 @@ bool SSLSClient::disconnect() // disconnects from client
 
 // constant
 bool SSLSClient::hasMessage(
-    int time) const // Waits for a message for a given time
+    int waitTime) const // Waits for a message for a given time
 {
     fd_set set;
     FD_ZERO(&set);
     FD_SET(SSL_get_rfd(ssl), &set);
-    timeval time = {time / 1000, time};
+    timeval time = {waitTime / 1000, waitTime};
     return SSL_pending(ssl) > 0 || select(0, &set, 0, 0, &time) == 1;
 }
 

+ 4 - 4
Network/WebSocket.cpp

@@ -1,4 +1,4 @@
-#include "WebSocket.h"
+#include "WebSocket.h"
 
 #include <iostream>
 
@@ -47,7 +47,7 @@ __declspec(dllexport) WebSocketClient::WebSocketClient(
 WebSocketClient::~WebSocketClient()
 {
     disconnect();
-    while (queue->getEintragAnzahl())
+    while (queue->getEntryCount())
     {
         Frame f = queue->get(0);
         delete[] f.data;
@@ -357,7 +357,7 @@ __declspec(dllexport) void WebSocketClient::thread()
         {
             c2.unlock();
             c.lock();
-            while (queue->getEintragAnzahl())
+            while (queue->getEntryCount())
             {
                 Frame f = queue->get(0);
                 c.unlock();
@@ -465,7 +465,7 @@ __declspec(dllexport) void WebSocketClient::disconnect()
     client->disconnect();
     client = (Client*)client->release();
     c2.unlock();
-    warteAufThread(1000);
+    waitForThread(1000);
 }
 
 __declspec(dllexport) bool WebSocketClient::isConnected() const