optimizing code
This commit is contained in:
56
.vscode/settings.json
vendored
56
.vscode/settings.json
vendored
@@ -1,56 +0,0 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cstring": "cpp",
|
||||
"iostream": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"csignal": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"map": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
}
|
||||
}
|
@@ -2,13 +2,12 @@
|
||||
|
||||
Client::Client() : _isRegistered(false) {}
|
||||
|
||||
Client::Client(int fd, std::string addr) : _fd(fd), _addr(addr) {}
|
||||
Client::Client(int fd) : _fd(fd) {}
|
||||
|
||||
Client::~Client() {}
|
||||
|
||||
int Client::getFd() const {return _fd;}
|
||||
|
||||
|
||||
void Client::setPassword(const std::string& password) {
|
||||
pass = password;
|
||||
}
|
||||
|
@@ -10,11 +10,10 @@ class Client {
|
||||
std::string name;
|
||||
std::string nick;
|
||||
std::string user;
|
||||
std::string _addr;
|
||||
bool _isRegistered;
|
||||
public:
|
||||
Client();
|
||||
Client(int fd, std::string addr);
|
||||
Client(int fd);
|
||||
~Client();
|
||||
|
||||
int getFd() const;
|
||||
|
14
Server.cpp
14
Server.cpp
@@ -37,7 +37,7 @@ void Server::parseArgs(int ac, char **av) {
|
||||
throw std::runtime_error("Error: Invalid arguments");
|
||||
|
||||
long _port = atol(av[1]);
|
||||
if (!(_port >= 1 && _port <= 65535))
|
||||
if (!(_port >= 0 && _port <= 65535))
|
||||
throw std::runtime_error("Error: Invalid arguments");
|
||||
|
||||
if (pwd.empty())
|
||||
@@ -96,7 +96,7 @@ void Server::createServerSocket() {
|
||||
if (listen(_serverSocketFd, SOMAXCONN) == -1)
|
||||
throw std::runtime_error("Error: listen() failed");
|
||||
|
||||
addPollfd(_serverSocketFd, POLLIN, 0);
|
||||
addPollfd(_serverSocketFd);
|
||||
}
|
||||
|
||||
void Server::bindServerSocket() {
|
||||
@@ -109,11 +109,11 @@ void Server::bindServerSocket() {
|
||||
}
|
||||
}
|
||||
|
||||
void Server::addPollfd(int fd, short events, short revents) {
|
||||
void Server::addPollfd(int fd) {
|
||||
struct pollfd newPollfd;
|
||||
newPollfd.fd = fd;
|
||||
newPollfd.events = events;
|
||||
newPollfd.revents = revents;
|
||||
newPollfd.events = POLLIN;
|
||||
newPollfd.revents = 0;
|
||||
_fds.push_back(newPollfd);
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ std::string art =
|
||||
send(newFd, art.c_str(), art.length(), 0);
|
||||
|
||||
send(newFd, passwordRequest.c_str(), passwordRequest.length(), 0);
|
||||
addPollfd(newFd, POLLIN, 0);
|
||||
_clients.push_back(Client(newFd, inet_ntoa((client_addr.sin_addr))));
|
||||
addPollfd(newFd);
|
||||
_clients.push_back(Client(newFd));
|
||||
|
||||
std::cout << "Client <" << newFd << "> Connected" << std::endl;
|
||||
}
|
||||
|
@@ -84,7 +84,7 @@ class Server {
|
||||
|
||||
void createServerSocket();
|
||||
void bindServerSocket();
|
||||
void addPollfd(int fd, short events, short revents);
|
||||
void addPollfd(int fd);
|
||||
void handleClientConnection();
|
||||
void handleClientData(int fd);
|
||||
void clientCleanup(int fd);
|
||||
|
Reference in New Issue
Block a user