separate main tests in differents files and added comparison in readme

This commit is contained in:
hugogogo
2022-07-20 14:34:16 +02:00
parent 726bf36b17
commit fecf5411bc
10 changed files with 1145 additions and 130 deletions

View File

@@ -4,7 +4,8 @@
Webserv::Webserv()
{
std::cout << "Server init\n";
_socket_fd = ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
// _socket_fd = ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
_socket_fd = ::socket(AF_INET, SOCK_STREAM, 0);
if (_socket_fd == -1)
{
::perror("err socket(): ");
@@ -12,11 +13,21 @@ Webserv::Webserv()
}
}
/* Webserv::Webserv(Webserv const &src)
{
} */
Webserv::~Webserv()
{
std::cout << "Server destroyed\n";
}
/* Webserv & Webserv::operator=(Webserv const &rhs)
{
} */
///////////////
// Functions //
@@ -56,36 +67,31 @@ void Webserv::start()
struct sockaddr_in addr;
socklen_t addr_len;
int accepted_fd;
// poll (or equivalent)
struct pollfd poll_s;
poll_s.fd = _socket_fd;
poll_s.events = POLLIN;
char buf[BUFSIZE]; // WIP buffer. need to try with std::vector or std::string.
int ret;
struct pollfd poll_s;
char buf[BUFSIZE]; // WIP buffer. need to try with std::vector or std::string.
int ret;
std::cout << "Server started\n";
while (1)
{
std::cout << "----------\n";
std::cout << "poll()\n"; // poll (or equivalent)
::poll(&poll_s, 1, -1);
std::cout << "accept()\n";
addr_len = sizeof addr;
accepted_fd = ::accept(_socket_fd, (sockaddr*)&addr, &addr_len);
if (accepted_fd == -1)
{
::perror("err accept(): ");
//throw WebservError();
continue;
}
std::cout << "accept()\n";
// "Your server must never block and the client can be bounced properly if necessary".
// NO-Block OK, but how to handle it ? Miss the bouncing part.
::fcntl(accepted_fd, F_SETFL, O_NONBLOCK);
std::cout << "poll()\n"; // poll (or equivalent)
poll_s.fd = accepted_fd;
poll_s.events = POLLIN; // We need a way to valid POLLOUT and POLLIN at the same time (both, not one of them)
::poll(&poll_s, 1, -1);
std::cout << "recv()\n";
ret = ::recv(accepted_fd, buf, BUFSIZE, 0);
if (ret == -1)