/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* CgiIn.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */ /* Updated: 2025/05/29 11:34:40 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include "server/AResource.hpp" #include #include #include 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"); close(_fd); } 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