nicolas-arnaud
2 years ago
12 changed files with 138 additions and 71 deletions
@ -1,12 +1,10 @@ |
|||
#pragma once |
|||
#include "webserv.hpp" |
|||
|
|||
|
|||
class JSONNode; |
|||
class Server; |
|||
|
|||
class Env { |
|||
std::vector<Server> _servers; |
|||
std::vector<Server *> _servers; |
|||
public: |
|||
Env(JSONNode *conf); |
|||
void listen(); |
|||
void answer(); |
|||
}; |
|||
|
@ -1,13 +1,14 @@ |
|||
#pragma once |
|||
#include "webserv.hpp" |
|||
|
|||
|
|||
class Server { |
|||
string _name; |
|||
std::vector<Socket> _sockets; |
|||
std::vector<Socket *> _sockets; |
|||
std::map<string, Route *> _routes; |
|||
|
|||
public: |
|||
Server(JSONNode *server); |
|||
~Server(); |
|||
void check(); |
|||
void answer(); |
|||
}; |
|||
|
@ -1,23 +1,33 @@ |
|||
#include "webserv.hpp" |
|||
|
|||
Env::Env(JSONNode *conf) { |
|||
JSONList servers = conf->obj()["servers"]->lst(); |
|||
int i = 0; |
|||
string th[8] = {"first", "second", "third", "fourth", |
|||
"fifth", "sixth", "seventh", "eigth"}; |
|||
for (std::vector<JSONNode *>::iterator it = servers.begin(); |
|||
it < servers.end(); it++) { |
|||
Server server(*it); |
|||
_servers.push_back(server); |
|||
// delete *it;
|
|||
cout << th[i] << " server launched.\n"; |
|||
i++; |
|||
} |
|||
while (1) { |
|||
for (std::vector<Server>::iterator it = _servers.begin(); |
|||
it < _servers.end(); it++) { |
|||
(*it).check(); |
|||
} |
|||
} |
|||
// delete conf;
|
|||
JSONList servers = conf->obj()["servers"]->lst(); |
|||
int i = 0; |
|||
string th[8] = {"first", "second", "third", "fourth", |
|||
"fifth", "sixth", "seventh", "eigth"}; |
|||
for (std::vector<JSONNode *>::iterator it = servers.begin(); |
|||
it < servers.end(); it++) { |
|||
Server *server = new Server(*it); |
|||
_servers.push_back(server); |
|||
// delete *it;
|
|||
cout << th[i] << " server launched.\n"; |
|||
i++; |
|||
} |
|||
// delete conf;
|
|||
} |
|||
void Env::listen() { |
|||
for (std::vector<Server *>::iterator it = _servers.begin(); |
|||
it < _servers.end(); it++) { |
|||
(*it)->check(); |
|||
} |
|||
cout << "finished env listen\n"; |
|||
} |
|||
|
|||
void Env::answer() { |
|||
cout << "env start answer\n"; |
|||
for (std::vector<Server *>::iterator it = _servers.begin(); |
|||
it < _servers.end(); it++) { |
|||
(*it)->answer(); |
|||
} |
|||
cout << "finished env answer\n"; |
|||
} |
|||
|
Loading…
Reference in new issue