Skip to content

Commit

Permalink
Merge pull request #16 from san-ghun/refactor/Server
Browse files Browse the repository at this point in the history
Refactor/server
  • Loading branch information
Taekeundo authored Oct 31, 2024
2 parents 214300e + 69ab94c commit 1ef6ea7
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 600 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -f

SRC_NAME = ./src/main.cpp \
./src/network/Poller.cpp \
./src/network/Socket.cpp \
./src/network/Server-network.cpp \
./src/server/Server.cpp \
./src/server/RequestHandler.cpp \
./src/server/HttpRequest.cpp \
Expand Down
28 changes: 2 additions & 26 deletions include/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Config.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: minakim <minakim@student.42berlin.de> +#+ +:+ +#+ */
/* By: sanghupa <sanghupa@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 16:23:00 by sanghupa #+# #+# */
/* Updated: 2024/08/07 17:26:39 by minakim ### ########.fr */
/* Updated: 2024/10/30 23:03:49 by sanghupa ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -57,10 +57,6 @@ class Config
// Singleton: Static method to get the single instance of the class
static Config& getInstance();

// Deleted copy constructor and copy assignment operator to prevent copying
// Config(const Config&) = delete;
// void operator=(const Config&) = delete;

void load(const std::string& filename);

std::string get(const std::string key) const;
Expand All @@ -73,21 +69,10 @@ class Config
ServerConfig* getServerByHost(const std::string serverHost) const;
ServerConfig* getServerByPort(const int serverPort) const;

// to server class ...?
// std::string getServerHost() const;
// int getPort() const;
// std::string getErrorPage(const int code) const;
// Location* getLocation(const std::string key) const;

std::vector<ServerConfig*> getServers() const;
std::map<std::string, std::string> getMimeTypeMap() const;
std::map<std::string, std::string> getConfigMap() const;

// to server class ...?
// std::map<int, std::string> getErrorPageMap() const;
// std::map<std::string, std::string> getServerSettingMap() const;
// std::map<std::string, Location*> getLocationMap() const;

// TODO: Implement
void setServer(ServerConfig* server, std::string line);
void setLocation(Location* location, std::string line);
Expand All @@ -98,19 +83,10 @@ class Config
~Config();

void _parseConfigFile(const std::string& filename);
// void _setHostPort();

std::vector<ServerConfig*> _servers;
std::map<std::string, std::string> _mimeTypeMap;
std::map<std::string, std::string> _configMap;

// to server class ...?
// std::map<int, std::string> _errorPageMap;
// std::map<std::string, std::string> _serverSettingMap;
// std::map<std::string, Location*> _locationMap;

// int _port;
// std::string _host;
};

#endif
43 changes: 0 additions & 43 deletions include/Poller.hpp

This file was deleted.

17 changes: 6 additions & 11 deletions include/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Server.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: minakim <minakim@student.42berlin.de> +#+ +:+ +#+ */
/* By: sanghupa <sanghupa@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 16:23:46 by sanghupa #+# #+# */
/* Updated: 2024/08/07 17:31:17 by minakim ### ########.fr */
/* Updated: 2024/10/30 23:05:09 by sanghupa ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,13 +20,9 @@
# include "RequestHandler.hpp"
# include "HttpRequest.hpp"
# include "HttpResponse.hpp"
# include "Socket.hpp"
# include "Poller.hpp"

class Config;
class Location;
class Socket;
class Poller;
// class RequestHandler;

struct ServerConfig;
Expand All @@ -52,19 +48,18 @@ class Server

private:
bool _running;
Socket _listenSocket;
std::vector<ListenInfo> _listenInfos;
std::map<int, ListenInfo> _clients;
Poller _poller;
std::vector<pollfd> _pollfds;
RequestHandler _requestHandler;

int _setupListeningSocket(const std::string host, int port);

void _acceptNewConnection();
void _handleClientData(int clientSocket, size_t idx);
ServerConfig& _fetchConfig(int target);

int _setupListenInfos();
int _setupListenSockets();
int _acceptNewConnection(int target);
int _handleClientData(int target, size_t i);

Config& _config;
std::vector<ServerConfig*> _serverConfigs;
Expand Down
47 changes: 0 additions & 47 deletions include/Socket.hpp

This file was deleted.

6 changes: 2 additions & 4 deletions include/webserv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* webserv.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: minakim <minakim@student.42berlin.de> +#+ +:+ +#+ */
/* By: sanghupa <sanghupa@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 21:04:39 by sanghupa #+# #+# */
/* Updated: 2024/10/23 10:15:54 by minakim ### ########.fr */
/* Updated: 2024/10/30 23:05:48 by sanghupa ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -47,8 +47,6 @@
// # include "StaticFileHandler.hpp"
// # include "HttpRequest.hpp"
// # include "HttpResponse.hpp"
// # include "Socket.hpp"
// # include "Poller.hpp"

// Macros
#define MAX_EVENTS 100 // TEST PURPOSE ONLY
Expand Down
75 changes: 0 additions & 75 deletions src/network/Poller.cpp

This file was deleted.

Loading

0 comments on commit 1ef6ea7

Please sign in to comment.