Added functional multiple client handling

This commit is contained in:
iherman-
2026-05-09 21:52:16 +02:00
parent 752eb89e72
commit bdc24594a4
5 changed files with 229 additions and 68 deletions

View File

@@ -6,7 +6,7 @@
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/06 17:18:11 by iherman- #+# #+# */
/* Updated: 2026/05/07 13:29:00 by iherman- ### ########.fr */
/* Updated: 2026/05/09 21:47:58 by iherman- ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,23 +14,7 @@
# define SERVER_HPP
// C lib functions
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <signal.h>
#include <poll.h>
// C++ lib functions
# include <iostream>
@@ -38,25 +22,39 @@
# include <string>
# include <cstring>
# include <vector>
# include <map>
# include "../User/User.hpp"
# define PORT_DEFAULT 9898
class Server
{
private:
static const int kConnectionQueueLimit;
int port_;
int serverSocket_;
std::string password_;
std::vector<struct pollfd> sockets_;
std::map<int, User> clients_;
bool handleClient(User& client);
void addClient();
std::vector<struct pollfd>::iterator removeClient(std::vector<struct pollfd>::iterator client);
Server(const Server& other);
Server &operator=(const Server& other);
public:
Server();
Server(int port, const std::string& password);
~Server();
Server &operator=(const Server& other);
void run();
};