Files
webserv/includes/server/CgiIn.hpp

53 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CgiIn.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */
/* Updated: 2025/05/29 12:07:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "server/AResource.hpp"
#include <log.hpp>
#include <stdexcept>
#include <unistd.h>
namespace webserv {
namespace server {
class CgiIn : public AClientResource {
public:
CgiIn(std::string body, int id) : _body(body) {
log("", "CgiIn", "constructor called");
_processed = false;
_fd = id;
_pfd_event = POLLOUT;
}
~CgiIn(void) {
log("", "CgiIn", "destructor called");
}
void process(void) {
_processed = true;
ssize_t bytes_written = write(_fd, _body.c_str(), _body.size());
if (bytes_written == -1) {
throw std::runtime_error("write error could not write body to cgi stdin");
}
}
clientResType type(void) const { return CGI_IN; }
short event(void) const { return POLLIN; }
bool isReady(void) const { return true; }
protected:
private:
std::string _body;
};
} // namespace server
} // namespace webserv