-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from san-ghun/dev/config
Dev/config
- Loading branch information
Showing
10 changed files
with
337 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,31 @@ | |
/* By: sanghupa <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/30 16:23:00 by sanghupa #+# #+# */ | ||
/* Updated: 2024/06/30 16:24:32 by sanghupa ### ########.fr */ | ||
/* Updated: 2024/07/08 23:35:53 by sanghupa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef CONFIG_HPP | ||
# define CONFIG_HPP | ||
|
||
# include "webserv.hpp" | ||
# include <string> | ||
# include <map> | ||
|
||
class Config | ||
{ | ||
public: | ||
Config(); | ||
~Config(); | ||
|
||
static void load(const std::string filename); | ||
static std::string get(const std::string key); | ||
static int getInt(const std::string key); | ||
static int getPort(); | ||
|
||
private: | ||
static std::map<std::string, std::string> _configMap; | ||
|
||
static void _parseConfigFile(const std::string filename); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sanghupa <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/30 16:23:00 by sanghupa #+# #+# */ | ||
/* Updated: 2024/07/05 20:17:00 by sanghupa ### ########.fr */ | ||
/* Updated: 2024/07/09 23:25:27 by sanghupa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -32,7 +32,7 @@ class Poller | |
void removeSocket(const Socket socket); | ||
void removeAllSockets(); | ||
std::vector<struct pollfd> getPollfds() const; | ||
std::vector<t_event> poll(int timeout); | ||
std::vector<t_event> poll(int timeout); | ||
|
||
private: | ||
std::vector<struct pollfd> _pollfds; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sanghupa <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/30 16:23:46 by sanghupa #+# #+# */ | ||
/* Updated: 2024/07/04 16:35:08 by sanghupa ### ########.fr */ | ||
/* Updated: 2024/07/10 21:23:36 by sanghupa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -22,6 +22,10 @@ | |
# include "RequestHandler.hpp" | ||
|
||
// class Config; | ||
class Location; | ||
class Socket; | ||
class Poller; | ||
// class RequestHandler; | ||
|
||
class Server | ||
{ | ||
|
@@ -68,11 +72,15 @@ class Server | |
bool _running; | ||
Socket _listenSocket; | ||
Poller _poller; | ||
RequestHandler _requestHandler; | ||
std::vector<pollfd> _pollfds; | ||
// RequestHandler _requestHandler; | ||
|
||
void _handleNewConnection(); | ||
void _handleClientData(Poller::t_event event); | ||
|
||
void _acceptNewConnection(); | ||
void _handleClientData_2(int clientSocket, size_t idx); | ||
|
||
std::vector<std::string> _serverNames; | ||
std::string _serverHost; | ||
std::string _serverPort; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: sanghupa <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/22 21:05:14 by sanghupa #+# #+# */ | ||
/* Updated: 2024/07/08 22:49:29 by sanghupa ### ########.fr */ | ||
/* Updated: 2024/07/09 23:16:14 by sanghupa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -50,6 +50,7 @@ int main(int argc, char *argv[]) | |
// Set the signal handler for SIGINT signal | ||
signal(SIGINT, ft_sigint_handler); | ||
|
||
(void)argv; | ||
// try-catch block for error handling | ||
// Create a Config object with the provided configuration file | ||
// Config config(argv[1]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,19 @@ | |
/* By: sanghupa <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/30 16:23:00 by sanghupa #+# #+# */ | ||
/* Updated: 2024/07/05 20:25:39 by sanghupa ### ########.fr */ | ||
/* Updated: 2024/07/09 23:46:15 by sanghupa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "webserv.hpp" | ||
#include "Poller.hpp" | ||
|
||
Poller::Poller() | ||
{} | ||
|
||
Poller::~Poller() | ||
{} | ||
|
||
void Poller::addSocket(const Socket socket, short events) | ||
{ | ||
pollfd pfd; | ||
|
@@ -47,7 +53,7 @@ std::vector<Poller::t_event> Poller::poll(int timeout) | |
} | ||
for (size_t i = 0; i < pollfds.size(); i++) | ||
{ | ||
if (pollfds[i].revents & POLLIN) | ||
if (pollfds[i].revents != 0) | ||
{ | ||
t_event event; | ||
event.socket = Socket(pollfds[i].fd); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,13 @@ | |
/* By: sanghupa <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/03 16:23:55 by sanghupa #+# #+# */ | ||
/* Updated: 2024/07/05 20:30:38 by sanghupa ### ########.fr */ | ||
/* Updated: 2024/07/10 23:07:54 by sanghupa ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "webserv.hpp" | ||
#include "Socket.hpp" | ||
#include "cstring" | ||
|
||
Socket::Socket() | ||
: _socketfd(-1) | ||
|
@@ -56,7 +57,7 @@ void Socket::_bindAddress(int port) | |
{ | ||
memset(&_address, 0, sizeof(_address)); | ||
_address.sin_family = AF_INET; | ||
_address.sin_addr.s_addr = htonl(INADDR_ANY); | ||
_address.sin_addr.s_addr = INADDR_ANY; | ||
_address.sin_port = htons(port); | ||
if (::bind(_socketfd, (struct sockaddr*)&_address, sizeof(_address)) < 0) | ||
{ | ||
|
@@ -93,14 +94,16 @@ void Socket::set_nonblocking() | |
|
||
Socket Socket::accept() | ||
{ | ||
std::cout << "\rSocket fd again: " << _socketfd << std::endl; | ||
int clientfd = ::accept(_socketfd, NULL, NULL); | ||
if (clientfd < 0) | ||
{ | ||
throw std::runtime_error("Failed to accept connection"); | ||
} | ||
// if (clientfd < 0) | ||
// { | ||
// throw std::runtime_error("Failed to accept connection"); | ||
// } | ||
return Socket(clientfd); | ||
} | ||
|
||
/* | ||
void Socket::connet(const std::string host, int port) | ||
{} | ||
|
@@ -109,6 +112,7 @@ ssize_t Socket::recv(char* buf, size_t len) | |
ssize_t Socket::send(const char* buf, size_t len) | ||
{} | ||
*/ | ||
|
||
void Socket::close() | ||
{ | ||
|
Oops, something went wrong.