Working on...
This commit is contained in:
parent
9e05ee86f7
commit
65c2cdbbaf
@ -36,7 +36,7 @@ class server {
|
|||||||
~server ();
|
~server ();
|
||||||
|
|
||||||
// one klijent
|
// one klijent
|
||||||
client* cli;
|
client* cli = NULL;
|
||||||
void accept(const uint timeout = 100);
|
void accept(const uint timeout = 100);
|
||||||
|
|
||||||
vector<thread> thr;
|
vector<thread> thr;
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
server::server (const ushort port, const uint limit, SSL_CTX* _securefds) {
|
server::server (const ushort port, const uint limit, SSL_CTX* _securefds) {
|
||||||
securefds = _securefds;
|
securefds = _securefds; // dodati parametar red čekanja queue koji će se koristiti kao limit u socketu
|
||||||
|
// a stavrni limit ćemo korisitit kao broj threadova
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
@ -33,14 +34,16 @@ server::server (const ushort port, const uint limit, SSL_CTX* _securefds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void server::accept(const uint timeout) {
|
void server::accept(const uint timeout) {
|
||||||
|
if (cli != NULL) {
|
||||||
|
cli->~client();
|
||||||
|
cli = NULL;
|
||||||
|
}
|
||||||
cli = new client(this, timeout, securefds);
|
cli = new client(this, timeout, securefds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void server::asyncli(const uint limit, void (*handlecli)(client*), const uint timeout) {
|
void server::asyncli(const uint limit, void (*handlecli)(client*), const uint timeout) {
|
||||||
do {
|
do {
|
||||||
thr.clear();
|
|
||||||
clis.clear();
|
|
||||||
for (uint i=0; i<limit; i++) {
|
for (uint i=0; i<limit; i++) {
|
||||||
clis.push_back(new client(this, timeout, securefds));
|
clis.push_back(new client(this, timeout, securefds));
|
||||||
thr.push_back(thread(handlecli, clis[clis.size()-1]));
|
thr.push_back(thread(handlecli, clis[clis.size()-1]));
|
||||||
@ -50,6 +53,8 @@ void server::asyncli(const uint limit, void (*handlecli)(client*), const uint ti
|
|||||||
thr[i].join();
|
thr[i].join();
|
||||||
clis[i]->~client();
|
clis[i]->~client();
|
||||||
}
|
}
|
||||||
|
thr.clear();
|
||||||
|
clis.clear();
|
||||||
|
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
BIN
test/client.o
BIN
test/client.o
Binary file not shown.
BIN
test/server.o
BIN
test/server.o
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user