diff --git a/TODO b/TODO index d943f55..ac410b0 100644 --- a/TODO +++ b/TODO @@ -8,4 +8,6 @@ new StringConverter class implement close() in TcpClientWindows -implement ConfigReader methods \ No newline at end of file +implement ConfigReader methods + +Fix NetworkBuffer and NetworkMessage code \ No newline at end of file diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog index dbe76bc..9da15b6 100644 Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog differ diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog index 1cd5e00..895359d 100644 Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog differ diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog index e22ff99..19a0415 100644 Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog differ diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/unsuccessfulbuild b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/unsuccessfulbuild new file mode 100644 index 0000000..e69de29 diff --git a/include/NetworkBuffer.hpp b/include/NetworkBuffer.hpp index b85ec15..32e1c13 100644 --- a/include/NetworkBuffer.hpp +++ b/include/NetworkBuffer.hpp @@ -12,7 +12,7 @@ struct NetworkBuffer NetworkBuffer(); ~NetworkBuffer(); - uint32 body_size; + byte *header = nullptr; byte *body = nullptr; }; diff --git a/include/TcpClient.hpp b/include/TcpClient.hpp index 53af62d..88cf530 100644 --- a/include/TcpClient.hpp +++ b/include/TcpClient.hpp @@ -34,7 +34,12 @@ public: bool Connect(); + bool DataAvailable(uint16 &size); + + //this method will receive the messages automaticaly and use the callback methods void ReceiveMessages(); + + //this is a more manual method with no callbacks const NetworkMessage &ReceiveMessage(); void SendMessage(const NetworkMessage &message); diff --git a/src/Config.cpp b/src/Config.cpp index d502120..1182417 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,21 +1,21 @@ #include "Config.hpp" -void Config::SetUsingConsole(bool value) +inline void Config::SetUsingConsole(bool value) { using_console = value; } -bool Config::GetUsingConsole() +inline bool Config::GetUsingConsole() { return using_console; } -void Config::SetLogToFile(bool value) +inline void Config::SetLogToFile(bool value) { log_to_file = value; } -bool Config::GetLogToFile() +inline bool Config::GetLogToFile() { return log_to_file; } diff --git a/src/NetworkMessage.cpp b/src/NetworkMessage.cpp index ad45585..b76ee86 100644 --- a/src/NetworkMessage.cpp +++ b/src/NetworkMessage.cpp @@ -26,7 +26,7 @@ NetworkMessage::~NetworkMessage() const NetworkBuffer &NetworkMessage::EncodeMessage(const NetworkMessage &message) { NetworkBuffer buffer; - uint16 size = buffer.body_size + 1; + uint16 size = sizeof(buffer.body_size) + sizeof(buffer.body); byte *encoded_message = new byte[size](); buffer.body_size = size; diff --git a/src/TcpClientWindows.cpp b/src/TcpClientWindows.cpp index 3c9d7bd..2ff5755 100644 --- a/src/TcpClientWindows.cpp +++ b/src/TcpClientWindows.cpp @@ -128,16 +128,19 @@ bool TcpClient::Connect() return true; } +bool TcpClient::DataAvailable(uint16 &size) +{ + return ioctlsocket(tcp_socket, FIONREAD, (u_long*)size) != NO_ERROR && size > 0; +} + const NetworkBuffer &TcpClient::receive_data_array() { NetworkBuffer buffer; - int32 header_received = recv(tcp_socket, reinterpret_cast(buffer.body_size), 4, 0); - - if (header_received != 4 || WSAGetLastError() != 0) // this header is completely unrelated to the network message header - this header is the body size of the network message - { - // there was a problem receiving the body size of the message or theres no header to receive - } + uint16 body_size; + if (DataAvailable(body_size)) + buffer.body_size = body_size; + else return NetworkBuffer(); buffer.body = new byte[buffer.body_size](); int32 body_received = recv(tcp_socket, reinterpret_cast(buffer.body), buffer.body_size, 0); @@ -157,11 +160,11 @@ void TcpClient::receive_data(TcpClient *client) if (message.valid) { if (message.tag == CONNECT) // some user has connected - client->OnConnect(message.sender); + std::async(std::launch::async, client->OnConnect, message.sender); else if (message.tag == DISCONNECT) // some user has disconnected - client->OnDisconnect(message.sender); + std::async(std::launch::async, client->OnDisconnect, message.sender); else - client->OnMessage(message.sender, message.tag, message.subject, message.data); // we received data + std::async(std::launch::async, client->OnMessage, message.sender, message.tag, message.subject, message.data); // we received data } } } diff --git a/src/Utility.cpp b/src/Utility.cpp index e9a6156..3108a28 100644 --- a/src/Utility.cpp +++ b/src/Utility.cpp @@ -145,3 +145,18 @@ const std::string & Utility::StringConverter::ToString(byte * bytes, uint16 star { // TODO: insert return statement here } + +const void Utility::ConfigReader::ReadConfig(const std::string & file_name) +{ + return void(); +} + +const std::map& Utility::ConfigReader::ReadNodes() +{ + // TODO: insert return statement here +} + +const std::string & Utility::ConfigReader::operator[](uint16 index) +{ + // TODO: insert return statement here +}