diff --git a/lib/tcp_socket.hpp b/lib/tcp_socket.hpp index d1819f5..51e2c16 100644 --- a/lib/tcp_socket.hpp +++ b/lib/tcp_socket.hpp @@ -53,6 +53,7 @@ class server { void sync(void (*handlecli)(client&), const uint timeout = 100); void async(const uint limit, void (*handlecli)(client&, mutex&), const uint timeout = 100); + void pool(const uint limit, void (*handlecli)(client&, mutex&), const uint timeout = 100); }; @@ -100,6 +101,27 @@ class client { ~client (); bool push (const string msg); string pull (size_t byte_limit = 1024); + + /** + * ustvari ne znam jel konekcija aktivna + * kod za connect i disconnect je konstruktoru - destruktoru + */ +}; + + +class Pool { + public: + uint numcli; + vector> drops; + + // konstruktor za klijente bez servera + Pool (const uint _numcli, const string address, const ushort port, const uint timeout = 100, SSL_CTX* securefds = NULL); + // konstruktor za klijente sa serverom + Pool (const server *_srv, const uint _numcli, const uint timeout = 100, SSL_CTX* securefds = NULL); + ~Pool(); + + void run(); + }; #endif \ No newline at end of file diff --git a/src/tcp_socket.cpp b/src/tcp_socket.cpp index f1fe0c6..3a3e6bc 100644 --- a/src/tcp_socket.cpp +++ b/src/tcp_socket.cpp @@ -380,3 +380,40 @@ string client::pull(size_t byte_limit) { return string(res); } + + +Pool::Pool(const uint _numcli, const string address, const ushort port, const uint timeout, SSL_CTX* securefds) { + if (_numcli > 1 ) { + numcli = _numcli; + } + else { + throw string("[ERROR] Invalid number of instances in pool "); + } + + for (uint i=0; i 1 ) { + numcli = _numcli; + } + else { + throw string("[ERROR] Invalid number of instances in pool "); + } + + for (uint i=0; i thr; - for (uint i=0; i thr; + // for (uint i=0; i