From 9e5cd40847268e111a9b6307716b94ae4c341fc9 Mon Sep 17 00:00:00 2001 From: xX-TheDoctor-Xx Date: Sat, 23 Jul 2016 13:15:59 +0100 Subject: [PATCH] Added DataAvailable method in TcpClient which will return the number of bytes available in the stream Config functions are now inline NetworkMessage and NetworkBuffer are being reworked --- TODO | 4 +++- .../Release/VoidNetVS.tlog/CL.command.1.tlog | Bin 5934 -> 5326 bytes .../Release/VoidNetVS.tlog/CL.read.1.tlog | Bin 224412 -> 196612 bytes .../Release/VoidNetVS.tlog/CL.write.1.tlog | Bin 7550 -> 7242 bytes .../Release/VoidNetVS.tlog/unsuccessfulbuild | 0 include/NetworkBuffer.hpp | 2 +- include/TcpClient.hpp | 5 +++++ src/Config.cpp | 8 +++---- src/NetworkMessage.cpp | 2 +- src/TcpClientWindows.cpp | 21 ++++++++++-------- src/Utility.cpp | 15 +++++++++++++ 11 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/unsuccessfulbuild 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 dbe76bcfe20a00c99d7a767869d6efe746fd60dc..9da15b6b58e451928bd830adcece6cc8aefcfac5 100644 GIT binary patch delta 34 qcmZ3dcTRHy6W?S3akr3@!}*Kvpo2@6O-@WIHi90%=c%C?FjIr2TQwFAfOqpK>Z-62LoAz%&7;tALtGggWP}ygaEN8&=^7nVAJmobi60nO9XYRV6i?F z?D8Ol0n0JPb`4#2> delta 65 zcmX?Q@y}|*7xBpn+ 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 +}