mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-28 02:58:35 +02:00
start server part of clusterizer
This commit is contained in:
56
srcs/class/Clusterizer/Clusterizer.cpp
Normal file
56
srcs/class/Clusterizer/Clusterizer.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Clusterizer.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/20 18:24:39 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/20 22:42:42 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "RT.hpp"
|
||||
|
||||
Clusterizer::Clusterizer(Arguments args)
|
||||
{
|
||||
_isActive = 1;
|
||||
_isServer = 0;
|
||||
_error = 0;
|
||||
_serverSocket = 0;
|
||||
|
||||
if(args.getBoolean("server"))
|
||||
{
|
||||
_isServer = 1;
|
||||
initServer(*args.getString("server"));
|
||||
}
|
||||
else if(args.getBoolean("client"))
|
||||
{
|
||||
_isServer = 0;
|
||||
_serverIp = *args.getString("client");
|
||||
initClient();
|
||||
}
|
||||
else
|
||||
_isActive = 0;
|
||||
}
|
||||
|
||||
Clusterizer::~Clusterizer(void)
|
||||
{
|
||||
if(_serverSocket)
|
||||
close(_serverSocket);
|
||||
}
|
||||
|
||||
void Clusterizer::update(void)
|
||||
{
|
||||
if(!_isActive)
|
||||
return ;
|
||||
if(_isServer)
|
||||
updateServer();
|
||||
else
|
||||
updateClient();
|
||||
}
|
||||
|
||||
bool Clusterizer::getError(void)
|
||||
{
|
||||
return(_error);
|
||||
}
|
23
srcs/class/Clusterizer/client.cpp
Normal file
23
srcs/class/Clusterizer/client.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* client.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/20 21:21:45 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "RT.hpp"
|
||||
|
||||
void Clusterizer::initClient(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Clusterizer::updateClient(void)
|
||||
{
|
||||
|
||||
}
|
48
srcs/class/Clusterizer/server.cpp
Normal file
48
srcs/class/Clusterizer/server.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* server.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/20 22:43:00 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "RT.hpp"
|
||||
|
||||
void Clusterizer::initServer(std::string port)
|
||||
{
|
||||
try
|
||||
{
|
||||
initServerSocket(stoi(port));
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cerr << "server initialization error : " << e.what() << std::endl;
|
||||
_error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Clusterizer::initServerSocket(uint16_t port)
|
||||
{
|
||||
struct sockaddr_in s_addr;
|
||||
|
||||
_serverSocket = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
||||
if (_serverSocket < 0)
|
||||
throw std::runtime_error("can't create socket");
|
||||
s_addr.sin_family = AF_INET;
|
||||
s_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
s_addr.sin_port = port >> 8 | port << 8;
|
||||
if (bind(_serverSocket, (struct sockaddr *)&s_addr, \
|
||||
sizeof(struct sockaddr_in)) < 0)
|
||||
throw std::runtime_error("can't bind socket");
|
||||
if (::listen(_serverSocket, 50) < 0)
|
||||
throw std::runtime_error("can't listen on socket");
|
||||
}
|
||||
|
||||
void Clusterizer::updateServer(void)
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user