#include "server.hpp" Server::Server(size_t _max_clients,int port){ //-------------------------- // Create connection socket //-------------------------- connection_socket=socket(AF_INET, SOCK_STREAM, 0); if(connection_socket<0){ cerr<<"[Error] Can not open socket"<=0){ //Set socket for nonblocking fcntl(socket, F_SETFL, O_NONBLOCK); clients[nb_clients].socket=socket; clients[nb_clients].has_message=false; clients[nb_clients].is_worker=false; clients[nb_clients].current_task=nullptr; ++nb_clients; } } } void Server::listen_clients(){ char buffer; for(size_t c=0;c0){ if(not clients[c].has_message){ get_message(c); } } if(l==0) remove_client(c); } } void Server::remove_client(size_t c){ ClientInformation& client=clients[c]; if(client.is_worker){ Task* task=client.current_task; if(task!=nullptr){ if(task->get_statut()!=Task::Done){ task->set_statut(Task::Unaffected); } } --nb_workers; } --nb_clients; close(clients[c].socket); for(size_t i=c;iset_output(message.get_data_buffer(),message.get_data_size()); task->set_statut(Task::Done); ++nb_finished_tasks; if(treat!=nullptr){ bool stop=treat(*task); if(stop) nb_finished_tasks=nb_tasks; } }