|
|
@ -32,36 +32,42 @@ server::server (const ushort port, const uint queue, SSL_CTX* _securefds) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<typename... Args> |
|
|
|
/**
|
|
|
|
void server::sync(const uint timeout, void (*func)(Args ...vars)) { |
|
|
|
* Metoda za sinkroni rad s klijentima, prima pokazivač na funkciju i timeout; |
|
|
|
|
|
|
|
* Funkcija handlecli prima referencu tipa client - važno za definiranje funkcija koje se šalju; |
|
|
|
|
|
|
|
* Nije moguće proslijediti druge parametre; |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void server::sync(void (*handlecli)(client&), const uint timeout) { |
|
|
|
do { |
|
|
|
do { |
|
|
|
if (cli != NULL) { |
|
|
|
client cli(this, timeout, securefds); |
|
|
|
cli->~client(); |
|
|
|
handlecli(cli); |
|
|
|
cli = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cli = new client(this, timeout, securefds); |
|
|
|
|
|
|
|
// callback
|
|
|
|
|
|
|
|
func(); |
|
|
|
|
|
|
|
} while (true); |
|
|
|
} while (true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// template<typename... Args>
|
|
|
|
/**
|
|
|
|
// void server::async(const uint limit, void (*handlecli)(Args ...args), const uint timeout) {
|
|
|
|
* Metoda za asinkdorni rad s klijentima, prima limit, pokazivač na funkciju i timeout; |
|
|
|
// do {
|
|
|
|
* Funkcija handlecli prima referencu tipa client - važno za definiranje funkcija koje se šalju; |
|
|
|
// for (uint i=0; i<limit; i++) {
|
|
|
|
* Nije moguće proslijediti druge parametre; |
|
|
|
// clis.push_back(new client(this, timeout, securefds));
|
|
|
|
*/ |
|
|
|
// thr.push_back(thread(handlecli, args...));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for (uint i=0; i<limit; i++) {
|
|
|
|
void server::async(const uint limit, void (*handlecli)(client&, mutex&), const uint timeout) { |
|
|
|
// thr[i].join();
|
|
|
|
mutex io; |
|
|
|
// clis[i]->~client();
|
|
|
|
do { |
|
|
|
// }
|
|
|
|
for (uint i=0; i<limit; i++) { |
|
|
|
// thr.clear();
|
|
|
|
thr.push_back(thread([&](){ |
|
|
|
// clis.clear();
|
|
|
|
client cli(this, timeout, securefds); |
|
|
|
|
|
|
|
handlecli(cli, io); |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (uint i=0; i<limit; i++) { |
|
|
|
|
|
|
|
thr[i].join(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
thr.clear(); |
|
|
|
|
|
|
|
|
|
|
|
// } while (true);
|
|
|
|
} while (true); |
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -71,9 +77,6 @@ void server::sync(const uint timeout, void (*func)(Args ...vars)) { |
|
|
|
|
|
|
|
|
|
|
|
server::~server () { |
|
|
|
server::~server () { |
|
|
|
|
|
|
|
|
|
|
|
cli->~client(); |
|
|
|
|
|
|
|
cli = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sock<=0) { |
|
|
|
if (sock<=0) { |
|
|
|
throw string("[ERROR] The socket is already closed ");
|
|
|
|
throw string("[ERROR] The socket is already closed ");
|
|
|
|
} |
|
|
|
} |
|
|
|