From 386c39b58b52feaeae0b7a2bc5aa1c2302e01ef0 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 21 Feb 2022 12:18:20 +0300 Subject: [PATCH] feat: move server_sock to EPOLLET --- src/Server/Server.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index cfe1ebb..8b5ffc8 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -117,7 +117,7 @@ int Server::delete_client(std::map &client_map, int fd) void Server::setup_server_socks(std::map &configurations_map) { - unsigned int server_events = EPOLLIN; + unsigned int server_events = EPOLLIN | EPOLLET; for (std::vector::iterator it = _configs.begin(); it != _configs.end(); ++it) @@ -207,18 +207,21 @@ void Server::run(void) /* DBOUT << "FD is " << fd << ENDL; */ /* print_epoll_events(events); */ - if ((events & EPOLLIN) - && (sock_it = configurations_map.find(fd)) != configurations_map.end()) + if ((sock_it = configurations_map.find(fd)) != configurations_map.end()) { - int client_sock = accept(fd, - (sock_it->second).getSockaddr(), (sock_it->second).getSocklen()); - if (client_sock > 0) + while (1) { - client_map[client_sock] = new Client((sock_it->second).min_config); - add_to_epoll_list(client_sock, client_events); + int client_sock = accept(fd, + (sock_it->second).getSockaddr(), (sock_it->second).getSocklen()); + if (client_sock > 0) + { + client_map[client_sock] = new Client((sock_it->second).min_config); + add_to_epoll_list(client_sock, client_events); + } + else + break; + /* throw std::logic_error("accept didnt work"); */ } - else - throw std::logic_error("accept didnt work"); } else {