🏗️」 wip(Client): taking pollfd and not just fd in argument

This commit is contained in:
y-syo
2025-04-25 12:44:45 +02:00
parent a77f44579f
commit 9d0a08650f
3 changed files with 15 additions and 15 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */
/* Updated: 2025/04/25 12:32:29 by mmoussou ### ########.fr */
/* Updated: 2025/04/25 12:43:54 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,8 +24,8 @@ namespace server {
class Client {
public:
Client();
Client(int, sockaddr_in, config::Config *);
void parse(int, sockaddr_in, config::Config *);
Client(struct pollfd, sockaddr_in, config::Config *);
void parse(struct pollfd, sockaddr_in, config::Config *);
virtual ~Client(void);
void answer(void);
@ -33,7 +33,7 @@ class Client {
private:
void _getRequest(std::string);
int _fd;
struct pollfd _fd;
struct sockaddr_in _client_addr;
http::IRequest *_request;
//http::Response *_response;

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 16:07:01 by mmoussou #+# #+# */
/* Updated: 2025/04/24 15:31:56 by mmoussou ### ########.fr */
/* Updated: 2025/04/25 12:36:17 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
/* Updated: 2025/04/25 12:33:38 by mmoussou ### ########.fr */
/* Updated: 2025/04/25 12:44:12 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@ using namespace server;
Client::Client(void) {}
Client::Client(int fd, sockaddr_in socket, config::Config *conf)
Client::Client(struct pollfd fd, sockaddr_in socket, config::Config *conf)
: _fd(fd), _client_addr(socket)
{
std::string received_data;
@ -25,7 +25,7 @@ Client::Client(int fd, sockaddr_in socket, config::Config *conf)
ssize_t bytes_received;
do {
std::memset(buffer, 0, BUFFER_SIZE);
bytes_received = recv(fd, buffer, BUFFER_SIZE - 1, 0);
bytes_received = recv(this->_fd.fd, buffer, BUFFER_SIZE - 1, 0);
if (bytes_received == -1) {
_log->error("failed to receive request");
throw std::runtime_error("failed to receive request");
@ -42,7 +42,7 @@ Client::Client(int fd, sockaddr_in socket, config::Config *conf)
// throw error
}
void Client::parse(int fd, sockaddr_in socket, config::Config *conf)
void Client::parse(struct pollfd fd, sockaddr_in socket, config::Config *conf)
{
this->_fd = fd;
this->_client_addr = socket;
@ -51,7 +51,7 @@ void Client::parse(int fd, sockaddr_in socket, config::Config *conf)
ssize_t bytes_received;
do {
std::memset(buffer, 0, BUFFER_SIZE);
bytes_received = recv(fd, buffer, BUFFER_SIZE - 1, 0);
bytes_received = recv(this->_fd.fd, buffer, BUFFER_SIZE - 1, 0);
if (bytes_received == -1) {
_log->error("failed to receive request");
throw std::runtime_error("failed to receive request");
@ -74,24 +74,24 @@ void Client::_getRequest(std::string request_str) {
if (method == "GET")
{
_log->info("get request received");
this->_request = new http::Get(request_str);
_log->info("get request received");
}
else if (method == "DELETE")
{
_log->info("delete request received");
this->_request = new http::Delete(request_str);
_log->info("delete request received");
}
else if (method == "POST")
{
_log->info("post request received");
this->_request = new http::Post(request_str);
_log->info("post request received");
}
else
{
_log->info("unsupported request received");
this->_request = new http::Get();
this->_request->setMethod("501");
_log->info("unsupported request received");
}
// set target to correct target with the conf
}
@ -106,7 +106,7 @@ void Client::answer(void) {
response = this->_request->execute().str();
else
response = "HTTP/1.1 501 Not Implemented\r\nContent-Type: text/html\r\n\r\n<html><body><h1>501 Not Implemented</h1></body></html>";
send(this->_fd, response.c_str(), response.length(), 0);
send(this->_fd.fd, response.c_str(), response.length(), 0);
}
Client::~Client(void) {