diff --git a/TODO b/TODO
index d22f382..e1d0eae 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,3 @@
initialization code for other operating systems - currently VoidNet only supports windows
initialization code for tcp client for other operating systems - "
-implement thread pool - god dammit so many tries and it doesnt work
\ No newline at end of file
+handle SendNetworkMessage errors for windows
\ No newline at end of file
diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog
index 02d72cf..4721096 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/Lib-link.write.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib-link.write.1.tlog
index a56c9d6..47d98bc 100644
Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib-link.write.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib-link.write.1.tlog differ
diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog
index 713dfb9..abc774e 100644
Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog differ
diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog
index 46e8865..0e35fa9 100644
Binary files a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog and b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog differ
diff --git a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj
index 4fd9b6b..24cf878 100644
--- a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj
+++ b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj
@@ -39,7 +39,6 @@
-
diff --git a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters
index 06e1184..33f075c 100644
--- a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters
+++ b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters
@@ -53,9 +53,6 @@
src
-
- src
-
src
diff --git a/include/TcpClient.hpp b/include/TcpClient.hpp
index 2c17a3f..3cc68ab 100644
--- a/include/TcpClient.hpp
+++ b/include/TcpClient.hpp
@@ -30,20 +30,15 @@ public:
NetworkBuffer ReceiveDataArray();
const NetworkMessage &ReceiveData();
- void StartSender();
- VoidCode SendMessage(const NetworkMessage &message);
+ void SendMessage(const NetworkMessage &message);
private:
- void SendNetworkMessage(const NetworkMessage &message);
- void SendNetworkMessageNow(const NetworkMessage &message);
+ static void SendNetworkMessage(const NetworkMessage &message, TcpClient *client);
VoidCode Initialize(const std::string &ip, uint16 port = default_port);
std::string ip;
uint16 port = 0;
bool initialized = false;
- bool run_sender = false;
-
- std::vector network_message_queue;
#ifdef _MSC_VER
SOCKET tcp_socket = INVALID_SOCKET;
diff --git a/include/VoidNetClient.hpp b/include/VoidNetClient.hpp
index ae27026..44ce6b4 100644
--- a/include/VoidNetClient.hpp
+++ b/include/VoidNetClient.hpp
@@ -22,13 +22,13 @@ struct VoidNetClientAPI
static bool Connect(const std::string &ip, uint16 port = default_port);
static void Disconnect();
- static bool SendMessageToServer(byte tag, byte subject, void *data);
- static bool SendMessageToID(uint16 id, byte tag, byte subject, void *data);
- static bool SendMessageToOthers(byte tag, byte subject, void *data);
- static bool SendMessageToAll(byte tag, byte subject, void *data);
- static bool SendMessageToAllAndMe(byte tag, byte subject, void *data);
+ static void SendMessageToServer(byte tag, byte subject, void *data);
+ static void SendMessageToID(uint16 id, byte tag, byte subject, void *data);
+ static void SendMessageToOthers(byte tag, byte subject, void *data);
+ static void SendMessageToAll(byte tag, byte subject, void *data);
+ static void SendMessageToAllAndMe(byte tag, byte subject, void *data);
- static bool SendMessage(byte distribution_mode, uint16 destination_id, byte tag, byte subject, void *data);
+ static void SendMessage(byte distribution_mode, uint16 destination_id, byte tag, byte subject, void *data);
static void Receive();
diff --git a/src/TcpClientWindows.cpp b/src/TcpClientWindows.cpp
index d003232..5b8712b 100644
--- a/src/TcpClientWindows.cpp
+++ b/src/TcpClientWindows.cpp
@@ -7,6 +7,7 @@
#include
#include
+#include
#undef SendMessage
@@ -114,7 +115,7 @@ NetworkBuffer TcpClient::ReceiveDataArray()
buffer.body = new byte[buffer.body_size]();
int32 body_received = recv(tcp_socket, reinterpret_cast(buffer.body), buffer.body_size, 0);
- if (body_received != buffer.body_size || WSAGetLastError() != 0)
+ if (body_received == SOCKET_ERROR || body_received != buffer.body_size || WSAGetLastError() != 0)
{
//there was a problem receiving the body of the message or theres no body to receive
return NetworkBuffer();
@@ -135,26 +136,17 @@ const NetworkMessage &TcpClient::ReceiveData()
return message;
}
-void TcpClient::SendNetworkMessage(const NetworkMessage &message)
-{
- network_message_queue.emplace_back(message);
-}
-
-void TcpClient::SendNetworkMessageNow(const NetworkMessage &message)
+void TcpClient::SendNetworkMessage(const NetworkMessage &message, TcpClient *client)
{
NetworkBuffer buffer = message.EncodeMessage(message);
- int32 sent_bytes = send(tcp_socket, reinterpret_cast(buffer.body), buffer.body_size, 0);
- if (sent_bytes != buffer.body_size)
+ int32 bytes_sent = send(client->tcp_socket, reinterpret_cast(buffer.body), buffer.body_size, 0);
+ if (bytes_sent == SOCKET_ERROR || bytes_sent != buffer.body_size || WSAGetLastError() != 0)
{
-
+ //something went wrong couldnt send anything/some data
}
}
-VoidCode TcpClient::SendMessage(const NetworkMessage &message)
+void TcpClient::SendMessage(const NetworkMessage &message)
{
-}
-
-void TcpClient::StartSender()
-{
- //std::thread thread = std::thread(&SendNetworkMessageNow, message);
+ std::async(std::launch::async, &SendNetworkMessage, message, this);
}
\ No newline at end of file
diff --git a/src/VoidNetClient.cpp b/src/VoidNetClient.cpp
index 9ddc1f0..56a4549 100644
--- a/src/VoidNetClient.cpp
+++ b/src/VoidNetClient.cpp
@@ -11,32 +11,32 @@ bool VoidNetClientAPI::Connect(const std::string &ip, uint16 port)
return client->Connect() == VOID_SUCCESS;
}
-bool VoidNetClientAPI::SendMessageToServer(byte tag, byte subject, void *data)
+void VoidNetClientAPI::SendMessageToServer(byte tag, byte subject, void *data)
{
- return SendMessage(Server, 0, tag, subject, data);
+ SendMessage(Server, 0, tag, subject, data);
}
-bool VoidNetClientAPI::SendMessageToID(uint16 destination_id, byte tag, byte subject, void *data)
+void VoidNetClientAPI::SendMessageToID(uint16 destination_id, byte tag, byte subject, void *data)
{
- return SendMessage(ID, destination_id, tag, subject, data);
+ SendMessage(ID, destination_id, tag, subject, data);
}
-bool VoidNetClientAPI::SendMessageToOthers(byte tag, byte subject, void *data)
+void VoidNetClientAPI::SendMessageToOthers(byte tag, byte subject, void *data)
{
- return SendMessage(Others, 0, tag, subject, data);
+ SendMessage(Others, 0, tag, subject, data);
}
-bool VoidNetClientAPI::SendMessageToAll(byte tag, byte subject, void *data)
+void VoidNetClientAPI::SendMessageToAll(byte tag, byte subject, void *data)
{
- return SendMessage(All, 0, tag, subject, data);
+ SendMessage(All, 0, tag, subject, data);
}
-bool VoidNetClientAPI::SendMessageToAllAndMe(byte tag, byte subject, void *data)
+void VoidNetClientAPI::SendMessageToAllAndMe(byte tag, byte subject, void *data)
{
- return SendMessage(AllAndMe, 0, tag, subject, data);
+ SendMessage(AllAndMe, 0, tag, subject, data);
}
-bool VoidNetClientAPI::SendMessage(byte distribution_mode, uint16 destination_id, byte tag, byte subject, void *data)
+void VoidNetClientAPI::SendMessage(byte distribution_mode, uint16 destination_id, byte tag, byte subject, void *data)
{
NetworkMessage message;
message.tag = tag;
@@ -45,7 +45,7 @@ bool VoidNetClientAPI::SendMessage(byte distribution_mode, uint16 destination_id
message.distribution_mode = distribution_mode;
message.sender = id;
message.destination_id = destination_id;
- return client->SendMessage(message) == VOID_SUCCESS;
+ client->SendMessage(message);
}
void VoidNetClientAPI::Receive()