diff --git a/lib/tcp_socket.hpp b/lib/tcp_socket.hpp index 20c9993..4927772 100644 --- a/lib/tcp_socket.hpp +++ b/lib/tcp_socket.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,10 @@ class server { client* cli; void accept(const uint timeout = 100); + vector thr; + vector clis; + void asyncli(const uint limit, void (*handlecli)(client*) , const uint timeout = 100); + }; /** diff --git a/src/tcp_socket.cpp b/src/tcp_socket.cpp index e48f63c..3b31296 100644 --- a/src/tcp_socket.cpp +++ b/src/tcp_socket.cpp @@ -36,6 +36,25 @@ void server::accept(const uint timeout) { cli = new client(this, timeout, securefds); } + +void server::asyncli(const uint limit, void (*handlecli)(client*), const uint timeout) { + do { + thr.clear(); + clis.clear(); + for (uint i=0; i~client(); + } + + } while (true); +} + + /** * Destruktor varijable tipa server */ diff --git a/test/client.cpp b/test/client.cpp index 8a123b1..1ca327b 100644 --- a/test/client.cpp +++ b/test/client.cpp @@ -1,4 +1,5 @@ #include +#include #include "../lib/tcp_socket.hpp" @@ -8,19 +9,35 @@ int main() { try { - secure crypto; - cout << "init cert " << endl; + uint n = 10000; - client myserver("127.0.0.1", 5000, 5000, crypto.fds); + vector thr; + for (uint i=0; iipv4 << endl; - - string fromclient = myserver.cli->pull(); - // string fromclient = myclient.pull(); - cout << "tell client " << fromclient << endl; - // usleep(600*1000); - sleep(5); - myserver.cli->push(fromclient); + // cout << "init client " << endl; + + // // client myclient(&myserver, 100, crypto.fds); + // // comming myclient(&myserver, 100); + // myserver.accept(); + // // cout << "wait client " << myclient.ipv4 << endl; + // cout << "wait client " << myserver.cli->ipv4 << endl; + + // string fromclient = myserver.cli->pull(); + // // string fromclient = myclient.pull(); + // cout << "tell client " << fromclient << endl; + // // usleep(600*1000); + // sleep(5); + // myserver.cli->push(fromclient); // myclient.push(fromclient); // myclient.~comming(); @@ -38,6 +38,16 @@ int main() { // } // sleep(80); + + + server myserver(5000, 100); + myserver.asyncli(8, [](client *cli) { + cout << "Klijent " << cli->ipv4 << endl; + string fromclient = cli->pull(); + cout << "S klijenta " << fromclient << endl; + cli->push(fromclient); + }, 200); + } catch(const string err) { cout << err << endl; diff --git a/test/server.o b/test/server.o index ae26bb9..f3dc291 100755 Binary files a/test/server.o and b/test/server.o differ