clusterizer : server and client can now communicate

This commit is contained in:
2025-02-22 02:07:01 +01:00
parent 960c4eb99c
commit 05ba0447d2
6 changed files with 238 additions and 24 deletions

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 18:25:18 by tomoron #+# #+# */
/* Updated: 2025/02/20 22:41:05 by tomoron ### ########.fr */
/* Updated: 2025/02/22 01:43:51 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,40 +21,72 @@ typedef struct s_job
glm::vec3 pos;
glm::vec2 dir;
size_t samples;
size_t id;
} t_job;
typedef struct s_client
{
std::vector<uint8_t> buffer;
t_job *curJob;
bool ready;
} t_client;
typedef enum e_msg
{
RDY,
JOB,
JOB_RES_RQ,
ACK,
WAIT,
IMAGE,
ERR,
UNKNOWN
} t_msg;
class Clusterizer
{
public:
Clusterizer(Arguments args);
Clusterizer(Arguments &args);
~Clusterizer();
private:
void update(void);
bool getError(void);
private:
bool _isActive;
bool _isServer;
bool _error;
std::vector<t_job> _jobs;
private: //client
void initClient(void);
void initClient(std::string &dest);
void openClientConnection(const char *ip, int port);
void clientHandleBuffer(void);
void updateClient(void);
void clientGetJob(std::vector<uint8_t> &sendBuf);
void clientReceive(void);
std::string _serverIp;
int _serverFd;
std::string _serverIp;
int _serverPort;
std::vector<uint8_t> _receiveBuffer;
t_job _currentJob;
private: //server
void initServer(std::string port);
void updateServer(void);
void initServerSocket(uint16_t port);
int _serverSocket;
void initServerSocket(int port);
void acceptClients(void);
void updatePollfds(void);
int updateBuffer(int fd);
void handleBuffer(int fd, std::vector<uint8_t> &buf);
void deleteClient(int fd);
int _serverSocket;
struct pollfd *_pollfds;
std::map<int, t_client> _clients;
};
#endif