Skip to content

Commit 8f831d4

Browse files
committed
clients fct and url40.txt siege tests
1 parent a633f50 commit 8f831d4

15 files changed

Lines changed: 520 additions & 501 deletions

File tree

Clients/Clients.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,31 @@ int find_client(std::vector<struct client> clients, int fd)
77
return i;
88
return -1;
99
}
10+
11+
void clear_client(struct client &cli)
12+
{
13+
cli.await_response = false;
14+
cli.rp = Response();
15+
cli.rq = Request();
16+
}
17+
18+
void deco_client(std::vector<struct client> &clients, Poll *poll_fds, int i)
19+
{
20+
int offset = find_client(clients, poll_fds->getFds(i).fd);
21+
if (DEBUGP) {std::cout << "[Client" << poll_fds->getFds(i).fd << "] to be deco" << std::endl;}
22+
if (offset > -1)
23+
clients.erase(clients.begin() + offset);
24+
if (poll_fds->getFds(i).fd > 0)
25+
close(poll_fds->getFds(i).fd);
26+
poll_fds->remove_to_poll(i);
27+
}
28+
29+
void close_clients(std::vector<struct client> &clients)
30+
{
31+
for (std::vector<struct client>::iterator it = clients.begin(); it != clients.end(); ++it)
32+
if (it->fd > 0)
33+
close(it->fd);
34+
clients.clear();
35+
}
36+
37+

Clients/Clients.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
#include <vector>
55
#include "../Response/Response.hpp"
66
#include "../RequestParsing/Request.hpp"
7+
#include "../include/Poll.hpp"
8+
#include "../include/server.hpp"
79

810
struct client
911
{
10-
int fd;
11-
int server_fd;
12+
int fd;
13+
int server_fd;
1214
bool await_response;
1315
Request rq;
1416
Response rp;
1517
};
1618

17-
int find_client(std::vector<struct client> all_co, int fd);
19+
int find_client(std::vector<struct client> all_co, int fd);
20+
void clear_client(struct client &cli);
21+
void deco_client(std::vector<struct client> &clients, Poll *poll_fds, int i);
22+
void close_clients(std::vector<struct client> &clients);
1823

1924
#endif

ConfigFile/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include"Location.hpp"
33

44
// constructors + copy
5-
Server::Server(): _ip("0.0.0.0"), _port(8080), _portSTR("8080") {}
5+
Server::Server(): _ip("127.0.0.1"), _port(8080), _portSTR("8080") {}
66
Server::~Server()
77
{
88
_names.clear();

0 commit comments

Comments
 (0)