Added PollManager class
This commit is contained in:
parent
53a83308de
commit
4a17d88d80
7 changed files with 179 additions and 37 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* core.hpp :+: :+: :+: */
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/12 14:16:03 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/19 15:07:26 by omoudni ### ########.fr */
|
||||
/* Updated: 2025/05/19 20:15:14 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -16,11 +16,21 @@
|
|||
#define LOG std::endl << CLR_CYAN << "Debug: " << __FILE__ << ":" << __LINE__ << std::endl << CLR_RESET
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
#define LOG ""
|
||||
#endif
|
||||
|
||||
enum e_state {
|
||||
ERROR = 0,
|
||||
CMD,
|
||||
MSG
|
||||
};
|
||||
|
||||
|
||||
#include "pollManager.hpp"
|
||||
#include "color.hpp"
|
||||
#include "server.hpp"
|
||||
#include "parser.hpp"
|
||||
|
|
|
|||
30
include/core/pollManager.hpp
Normal file
30
include/core/pollManager.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pollManager.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/19 19:15:13 by omoudni #+# #+# */
|
||||
/* Updated: 2025/05/19 19:25:45 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <poll.h>
|
||||
#include <map>
|
||||
|
||||
class PollManager {
|
||||
private:
|
||||
std::vector<struct pollfd> _fds;
|
||||
std::map<int, short> _fd_events; // fd -> event
|
||||
|
||||
public:
|
||||
PollManager();
|
||||
void addFd(int fd, short events);
|
||||
void removeFd(int fd);
|
||||
void updateFd(int fd, short events);
|
||||
int pollEvents(int timeout = -1);
|
||||
const std::vector<struct pollfd>& getFds() const;
|
||||
};
|
||||
|
|
@ -1,17 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* server.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: omoudni <omoudni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/13 11:06:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/14 23:23:13 by omoudni ### ########.fr */
|
||||
/* Updated: 2025/05/19 20:12:46 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core.hpp"
|
||||
#include <string>
|
||||
|
||||
class Server {
|
||||
|
|
@ -19,6 +20,7 @@ class Server {
|
|||
unsigned short int _port;
|
||||
std::string _password;
|
||||
int server_fd;
|
||||
PollManager _pollManager;
|
||||
public:
|
||||
Server();
|
||||
Server(int port, const std::string &password);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue