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