From c27ce40bab1cbbccf9474ade38610597a9900605 Mon Sep 17 00:00:00 2001 From: xX-TheDoctor-Xx Date: Mon, 18 Jul 2016 03:44:27 +0100 Subject: [PATCH] Trying to implement the sender but its not working the way i want --- TODO | 3 +- .../Release/Tests.tlog/CL.command.1.tlog | Bin 2 -> 634 bytes .../Tests/Release/Tests.tlog/CL.read.1.tlog | Bin 0 -> 26824 bytes .../Tests/Release/Tests.tlog/CL.write.1.tlog | Bin 0 -> 252 bytes .../Release/Tests.tlog/link.command.1.tlog | Bin 1296 -> 2 bytes .../Tests/Release/Tests.tlog/link.read.1.tlog | Bin 4138 -> 2 bytes .../Release/Tests.tlog/link.write.1.tlog | Bin 502 -> 2 bytes TestsVS/Tests/Tests.vcxproj | 1 + .../Release/VoidNetVS.tlog/CL.command.1.tlog | Bin 6526 -> 6526 bytes .../Release/VoidNetVS.tlog/CL.read.1.tlog | Bin 204974 -> 204740 bytes .../Release/VoidNetVS.tlog/CL.write.1.tlog | Bin 7380 -> 8910 bytes .../VoidNetVS.tlog/Lib-link.write.1.tlog | Bin 1288 -> 1180 bytes .../Release/VoidNetVS.tlog/Lib.read.1.tlog | Bin 3054 -> 2836 bytes .../Release/VoidNetVS.tlog/lib.command.1.tlog | Bin 1822 -> 1670 bytes VoidNetVS/VoidNetVS/VoidNetVS.vcxproj | 2 - VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters | 6 -- include/TcpClient.hpp | 11 ++-- include/ThreadPool.hpp | 33 ---------- include/VoidNetClient.hpp | 1 - src/TcpClientWindows.cpp | 27 ++++++--- src/ThreadPool.cpp | 57 ------------------ 21 files changed, 29 insertions(+), 112 deletions(-) create mode 100644 TestsVS/Tests/Release/Tests.tlog/CL.read.1.tlog create mode 100644 TestsVS/Tests/Release/Tests.tlog/CL.write.1.tlog delete mode 100644 include/ThreadPool.hpp delete mode 100644 src/ThreadPool.cpp diff --git a/TODO b/TODO index d91ec20..d22f382 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,3 @@ initialization code for other operating systems - currently VoidNet only supports windows -initialization code for tcp client for other operating systems - " \ No newline at end of file +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 diff --git a/TestsVS/Tests/Release/Tests.tlog/CL.command.1.tlog b/TestsVS/Tests/Release/Tests.tlog/CL.command.1.tlog index 46b134b197f35e75e0784bedbf94a8dd124693b1..2d0bd358dd8aeab13755e547d1ae4a418c7501a0 100644 GIT binary patch literal 634 zcmb`FTT8=05QWdP;C~R`ZM{A9%{CVUH4)Q`lwt_A)qvJe1*tz?{bsXDi~1&EXRS(HwG9?O>D%61e0H0%XGWphiGuKj2mwdb0QCl#d4POHRvd!xMqn*A@NQ6wR{5aV_P2p literal 2 JcmezW4*&xG0sa60 diff --git a/TestsVS/Tests/Release/Tests.tlog/CL.read.1.tlog b/TestsVS/Tests/Release/Tests.tlog/CL.read.1.tlog new file mode 100644 index 0000000000000000000000000000000000000000..e3d9241b6bd8add6be70a6fe14178757e99db20d GIT binary patch literal 26824 zcmd5_+iu%95asg%`ww~CeF<_yQS4jdTiwKxE6K4_1oi*_M0d~OgqGyk3!A1mgCe!% zn9|{yD~BWH-`~I7)cxb$-K#6z+>Kq~Ca%G8gV!4W*Z57{JMRAO+Kt>2|NeA;;2qDi z##suSr^Gvso4FUfe{zp_ox7iSZSY#+JMZ{?=_-F*;Ct=y7}uWSn=6cI+%>-Yg6|%` zM(y74dm>)Adv}L36*wAW)C)$->p7#Jai$9Am|#4S*LW9mo+-vR_?hD@G2>^zKKC<< z8NKqjt0Uu=m|+RlE6i`HElYK2c@=F~ugDvz=|`mhG`x^gY* z(>tz7&7(9L=*zYHw$t3x#*0?gy^*5xr*hf1jVt%;vCvAs;;grL{fv2mPy6GDyw&F6 zu3h6gkDl%E4#Oijn|s@&Uc7wpm>*3IeS5|a|9^#aD=(Gvaa^k1`|_H=a_AB1wPK`{ z8V_x-g67j7&SA^+V-|4L-gnr*GV;-A1ePkV?erRqC-iPM5WWIS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literal 0 HcmV?d00001 diff --git a/TestsVS/Tests/Release/Tests.tlog/link.command.1.tlog b/TestsVS/Tests/Release/Tests.tlog/link.command.1.tlog index 7d676d71d8ac78012840c4c50ceeba1333be7f3e..46b134b197f35e75e0784bedbf94a8dd124693b1 100644 GIT binary patch literal 2 JcmezW4*&xG0sa60 literal 1296 zcmb`HTTA0m6ouFGfd8TN#kUq`KqTNp5~CAM+t9RLK!kB74q~m~?aAM+etREFNu$0f zKj91V->YJ}%NA9yyiK1yQHB!z4-YD?aRF6RqiL7j?Rr-zJ zf?x9uQ_kMSVy|YCJq5E_SjIBqlu(%_Z-J&n(zNu6Jf<=^JqmMV)m_D=a8mE&Otl_a zGi_^Ke{{#2bC4Tdf!>03^q@=lfBDte@0@u7cgDVk(e(~pgUn%GIO`tuTGu+~|DW4; z*qx*G-%q9I^?kDx^g<*RRZN(J6PC@}fLN@jL(ZWeR+AC6vuU=kVAo?>AUW)S6fjbz zAR@0h`QLg@HT!$d-*hH)IPtDU+IY+K1Ya?JO(|h#Gilr*6Cb9l1f4jR!z>2>+}bz$b;N3S z6>qt3Z7376T8!QI_Rb=Q_MUMD+T89Px(yOqdEq1iVaj$LB_K80)FA_?VZrB|~!JJAJGoaHQ@eZ=Ujb zY9B2?v*YY+pHJx2h)VnFDpoQR4=Hn2v%;c|Qq2TW4Hk9v>CaXUid(w(JgRbwCgNoE z5&aK7Bwp}uyF<1!}CDWLb>kUbal z*d2NeF%*w#_^s~RXFcccXJUU>_Hz(J&k|pX=2V~fn%vMk#Fmv);+xaOsE=nJXjG|n zzYr4?1DxJJid8|bi^sfAy&!jQp2lLbLZiD^%Vyhu#-lnl zv)j`ytk--z56|G)>MMume|&Y@-!wyPZe5=^tzLF5`Wxx~X7zouu_n8?S;0 mhUE4G&+FHFt5`+Upo&cLXRME=yDQy}`?uQ49-p=M_5CkzV>cE6 diff --git a/TestsVS/Tests/Release/Tests.tlog/link.write.1.tlog b/TestsVS/Tests/Release/Tests.tlog/link.write.1.tlog index 33fb381ec20d47821170c7d1b6896072e40eb958..46b134b197f35e75e0784bedbf94a8dd124693b1 100644 GIT binary patch literal 2 JcmezW4*&xG0sa60 literal 502 zcmezWFOI>D!HOYa}Aq2<|0n))hG8iZmjKYs$2m;Fa0I?%b#uY_Q z4`_-LgBL>$4pUKWftZYL8m1aOplzN&b9ouKC@>e{BR!z2BY>EC=6Ny%0K<-&F7$+k KB=y{ga3KJ&a7x|) diff --git a/TestsVS/Tests/Tests.vcxproj b/TestsVS/Tests/Tests.vcxproj index d7e1ff8..95630e1 100644 --- a/TestsVS/Tests/Tests.vcxproj +++ b/TestsVS/Tests/Tests.vcxproj @@ -117,6 +117,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) F:\VoidNet\include; + MultiThreaded Console diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.command.1.tlog index f06a63fa254e7c937b785dd3dd427df9030af7c0..da2a2404e70c7cb00237a328df01d91f31f2e7bb 100644 GIT binary patch delta 25 hcmexo^v`I+H15eC_@y@S-C^52gWHd3^DU7jEC8Ij3hw{_ delta 26 icmexo^v`I+H15q^LIF&Z7w}4L-oSl_ZSx(GMJxcKvI|B4 diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.read.1.tlog index 72e3d4332fb22ddfdbbdce046571e1c119f23191..02d72cf1ae97a4ab229b214144e3088927dd9972 100644 GIT binary patch delta 464 zcmZ2?kmtyLo(&ym+pqC3ZokIEWT(Bk>uit7bSV+$3DX09F|lor(`PbaoF0(F#4~-L z2y@eR8$M=2Rg$%emsg+X$j41Pd)SB4-4H=ru#$%3h!+>SsIe+FNmob%*|krO8$S<%KH z!4LtIM-pdgmPRohXoE9@2hb!JpzS`>9j%zUH6aR|fg1gQlCD7Oe87fy0*&`$hzA?z z4HWmA9Gk8=@r=-R6$>UdlgaPS)=l5Q0`&8l#Y_j7Hvclu(VuK^x^DWr9Hs@+cbGG& zO`q_OiEpyiY@X=`yo_oS6C|eJ%La;GkZ10ie$SjqWby(=y~z(u9$^bEAJ)lf=?dFt dtYMl#j7>l@Q@{?w67oK*(^tteqqzp`001Ydj~D;| delta 303 zcmX@IpJ&}co(&ymw;%bz*k`icL4tW7f{C9b=#L| zGp%7HU}_Z8bcF^cw(aj8GaX>s4rFd)+#aCI_=j;)dfId^dFHf<2@)V1)TYOYGpB%9 aXC`NyRoH%M9n%aNTaB<%ZF+$`a|i&K5^uKv diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/CL.write.1.tlog index bfd30b5e2f2a338ae550cef6c9960812b047c142..99fa2d00dff1845195e354e37e2e99db13bc7aed 100644 GIT binary patch delta 118 zcmca&dCql%mEh(Vf#>oi+AQLqvzu^y>T)-qZIZGPI HmzV?q@op+m delta 37 tcmX@-dc|^smEh!ea_cr*2?}vewvh>%T)-qZSw=}=@&QJT&1)2u7y%P=4DtW~ 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 bd81a639ce591b353e6399f36980fa407f5b4827..a56c9d633a99be2d5d60bbb187809ad821b3e310 100644 GIT binary patch delta 11 ScmeC+n!~wa2lHeVmL~uh-ULDb delta 35 pcmbQk*}=782eWVpg9k$pgDZn0g9}3dgFg`ZOcrE{oV_S)2-yGt diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/Lib.read.1.tlog index d1d9bcbae707a7d331dea9636f936065cc35dab6..713dfb912c21fbab4d8a76c8a10dfb21f00ef422 100644 GIT binary patch delta 21 dcmaDSK1FQ94(7=xxWqPFu_&-@KEb8N2moFl2U!3B delta 69 zcmbOt_D+1m4rbvH1`mcH23H101{a0^27e&*nJmZ@Ir$x@*yeN03T#*v*mFd0e#fcC F2mn(*5Oe?l diff --git a/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog b/VoidNetVS/VoidNetVS/Release/VoidNetVS.tlog/lib.command.1.tlog index 3e3d46b12f0599c255ecc4322a46c8d391cc1cae..46e8865a242acaabd47da795579ba63c66d29f6a 100644 GIT binary patch delta 20 ccmbQo*T%bH2lHkXmL{gjDlB4?U$B`007)tak^lez delta 64 zcmZqUoyWIf2eWVpg9k$pgDZn0g9}3dgFg`ZOcrE{oNUD=w)q@$4ii=difpL>*GUbo diff --git a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj index 788028c..4fd9b6b 100644 --- a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj +++ b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj @@ -27,7 +27,6 @@ - @@ -42,7 +41,6 @@ - diff --git a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters index 11506fe..06e1184 100644 --- a/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters +++ b/VoidNetVS/VoidNetVS/VoidNetVS.vcxproj.filters @@ -45,9 +45,6 @@ include - - include - @@ -80,9 +77,6 @@ src - - src - diff --git a/include/TcpClient.hpp b/include/TcpClient.hpp index 1d890a8..2c17a3f 100644 --- a/include/TcpClient.hpp +++ b/include/TcpClient.hpp @@ -3,9 +3,9 @@ #include "Defs.hpp" #include "NetworkMessage.hpp" -#include "ThreadPool.hpp" #include +#include #ifdef _MSC_VER #pragma once @@ -30,17 +30,20 @@ public: NetworkBuffer ReceiveDataArray(); const NetworkMessage &ReceiveData(); + void StartSender(); VoidCode SendMessage(const NetworkMessage &message); private: - static VoidCode SendNetworkMessage(const NetworkMessage &message, TcpClient *client); + void SendNetworkMessage(const NetworkMessage &message); + void SendNetworkMessageNow(const NetworkMessage &message); VoidCode Initialize(const std::string &ip, uint16 port = default_port); std::string ip; uint16 port = 0; - bool initialized; + bool initialized = false; + bool run_sender = false; - ThreadPool thread_pool; + std::vector network_message_queue; #ifdef _MSC_VER SOCKET tcp_socket = INVALID_SOCKET; diff --git a/include/ThreadPool.hpp b/include/ThreadPool.hpp deleted file mode 100644 index 6cfc0be..0000000 --- a/include/ThreadPool.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef THREAD_POOL_HPP -#define THREAD_POOL_HPP - -#ifdef _MSC_VER -#pragma once -#endif - -#include -#include -#include -#include -#include - -class ThreadPool -{ -public: - ThreadPool(int threads); - ~ThreadPool(); - void Enqueue(std::function f); - void Shutdown(); - const ThreadPool &operator=(ThreadPool &pool); - -private: - std::vector threadPool; - std::queue> tasks; - std::mutex tasksMutex; - std::condition_variable condition; - bool terminate; - bool stopped; - void Invoke(); -}; - -#endif \ No newline at end of file diff --git a/include/VoidNetClient.hpp b/include/VoidNetClient.hpp index c425648..ae27026 100644 --- a/include/VoidNetClient.hpp +++ b/include/VoidNetClient.hpp @@ -11,7 +11,6 @@ #include "Callbacks.hpp" #include "NetworkBuffer.hpp" #include "NetworkMessage.hpp" -#include "ThreadPool.hpp" #include #include diff --git a/src/TcpClientWindows.cpp b/src/TcpClientWindows.cpp index eb367da..d003232 100644 --- a/src/TcpClientWindows.cpp +++ b/src/TcpClientWindows.cpp @@ -6,6 +6,7 @@ #include "Tags.hpp" #include +#include #undef SendMessage @@ -45,12 +46,12 @@ VoidCode TcpClient::Initialize(const std::string &ip, uint16 port) return VOID_SUCCESS; } -TcpClient::TcpClient() : port(default_port), thread_pool(50) +TcpClient::TcpClient() : port(default_port) { } TcpClient::TcpClient(const std::string &ip, uint16 port) : - ip(ip), port(port), thread_pool(50) + ip(ip), port(port) { } @@ -134,16 +135,26 @@ const NetworkMessage &TcpClient::ReceiveData() return message; } -VoidCode TcpClient::SendNetworkMessage(const NetworkMessage &message, TcpClient *client) +void TcpClient::SendNetworkMessage(const NetworkMessage &message) +{ + network_message_queue.emplace_back(message); +} + +void TcpClient::SendNetworkMessageNow(const NetworkMessage &message) { NetworkBuffer buffer = message.EncodeMessage(message); - int32 sent_bytes = send(client->tcp_socket, reinterpret_cast(buffer.body), buffer.body_size, 0); + int32 sent_bytes = send(tcp_socket, reinterpret_cast(buffer.body), buffer.body_size, 0); + if (sent_bytes != buffer.body_size) + { + + } } VoidCode TcpClient::SendMessage(const NetworkMessage &message) { - thread_pool.Enqueue([]() - { - //SendNetworkMessage(message, this); - }); +} + +void TcpClient::StartSender() +{ + //std::thread thread = std::thread(&SendNetworkMessageNow, message); } \ No newline at end of file diff --git a/src/ThreadPool.cpp b/src/ThreadPool.cpp deleted file mode 100644 index 3d59a85..0000000 --- a/src/ThreadPool.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "ThreadPool.hpp" - -ThreadPool::ThreadPool(int threads) : - terminate(false), - stopped(false) -{ - for (int i = 0; i < threads; i++) - threadPool.emplace_back(std::thread(&ThreadPool::Invoke, this)); -} - -void ThreadPool::Enqueue(std::function f) -{ - std::unique_lock lock(tasksMutex); - tasks.push(f); - condition.notify_one(); -} - -void ThreadPool::Invoke() { - - std::function task; - while (true) - { - std::unique_lock lock(tasksMutex); - condition.wait(lock, [this] { return !tasks.empty() || terminate; }); - if (terminate && tasks.empty()) - { - return; - } - task = tasks.front(); - tasks.pop(); - task(); - } -} - -void ThreadPool::Shutdown() -{ - std::unique_lock lock(tasksMutex); - terminate = true; - condition.notify_all(); - - for (std::thread &thread : threadPool) - thread.join(); - - threadPool.empty(); - stopped = true; -} - -const ThreadPool &ThreadPool::operator=(ThreadPool &pool) -{ - return pool; -} - -ThreadPool::~ThreadPool() -{ - if (!stopped) - Shutdown(); -} \ No newline at end of file