bugfix invalid ptr in "ev.data.ptr" after vector<Client> resize/erase

+ persistent connections reintroduced
+ bugfix crash if invalid path in request
This commit is contained in:
LuckyLaszlo
2022-07-31 13:19:11 +02:00
parent af8dc072c1
commit ea3f3a390a
5 changed files with 54 additions and 22 deletions

View File

@@ -4,6 +4,14 @@
#define MAX_EVENTS 42 // arbitrary
#define TIMEOUT 3000
// Temp. To move in other file
bool operator==(const Client& lhs, const Client& rhs)
{ return lhs.fd == rhs.fd; }
bool operator==(const Client& lhs, int fd)
{ return lhs.fd == fd; }
bool operator==(int fd, const Client& rhs)
{ return fd == rhs.fd; }
void Webserv::run()
{
std::cerr << "Server started\n";
@@ -33,15 +41,14 @@ void Webserv::run()
i = 0;
while (i < nfds)
{
// if ((events[i].data.u32 == SERVER_FD) && (events[i].events & EPOLLIN)) // Dont work, see "SERVER_FD" define
// if ((events[i].data.fd == _socket_fd) && (events[i].events & EPOLLIN))
// TODO : handle EPOLLERR and EPOLLHUP
if ((std::find(_listen_sockets.begin(), _listen_sockets.end(), events[i].data.fd) != _listen_sockets.end())
&& (events[i].events & EPOLLIN))
_accept_connection(events[i].data.fd);
else if (events[i].events & EPOLLIN)
_request(static_cast<Client*>(events[i].data.ptr));
_request( &(*std::find(_clients.begin(), _clients.end(), events[i].data.fd)) );
else if (events[i].events & EPOLLOUT)
_response(static_cast<Client*>(events[i].data.ptr));
_response( &(*std::find(_clients.begin(), _clients.end(), events[i].data.fd)) );
++i;
if (!g_run)
break;