style: some clean-ups

This commit is contained in:
3lswear
2022-02-05 20:13:02 +03:00
parent 481fd619d4
commit d2637eee79
2 changed files with 13 additions and 17 deletions

View File

@@ -11,14 +11,12 @@
Server::Server() Server::Server()
{ {
bzero(_events, sizeof(_events)); bzero(_events, sizeof(_events));
_client = 0;
} }
Server::Server(std::string path) Server::Server(std::string path)
{ {
(void)path; (void)path;
_client = 0;
} }
void Server::print_epoll_events(unsigned int events) void Server::print_epoll_events(unsigned int events)
@@ -69,8 +67,8 @@ void Server::sendData(Client &client, int fd)
else else
send_len = BUFFSIZE; send_len = BUFFSIZE;
/* std::cout << YELLO << tmp << RESET << std::endl; */ /* DBOUT << YELLO << tmp << ENDL; */
/* std::cout << GREEN << client.getCounter() << RESET << std::endl; */ /* DBOUT << GREEN << client.getCounter() << ENDL; */
if (send(fd, tmp + client.getCounter(), send_len, MSG_NOSIGNAL) < 0) if (send(fd, tmp + client.getCounter(), send_len, MSG_NOSIGNAL) < 0)
@@ -89,7 +87,7 @@ void Server::readSocket(Client &client, int fd)
int bytes_read; int bytes_read;
char buf[BUFFSIZE + 1]; char buf[BUFFSIZE + 1];
DBOUT << TURQ << "IN readSocket" << RESET << std::endl; DBOUT << TURQ << "IN readSocket" << ENDL;
DBOUT << "client in readSocket "<< &client << ENDL; DBOUT << "client in readSocket "<< &client << ENDL;
bytes_read = recv(fd, buf, BUFFSIZE, 0); bytes_read = recv(fd, buf, BUFFSIZE, 0);
if (bytes_read == 0) if (bytes_read == 0)
@@ -108,13 +106,13 @@ void Server::readSocket(Client &client, int fd)
client.allRead = true; client.allRead = true;
} }
std::cerr << "recvCounter " << client.getRecvCounter() << std::endl; DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL;
std::cerr << "contentLength " << client.getRequest().getContentLength() << std::endl; DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL;
std::cerr << "allRead " << client.allRead << std::endl; DBOUT << GREEN << "allRead " << client.allRead << ENDL;
DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << RESET << std::endl; DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL;
bzero(buf, BUFFSIZE);
} }
int Server::delete_client(std::map<int,Client *> &client_map, int fd) int Server::delete_client(std::map<int,Client *> &client_map, int fd)
{ {
int ret; int ret;
@@ -149,12 +147,11 @@ void Server::add_to_epoll_list(int fd, unsigned int ep_events)
ev.data.fd = fd; ev.data.fd = fd;
assert(epoll_ctl(_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == 0); assert(epoll_ctl(_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == 0);
_client++; DBOUT << YELLO
std::cerr << YELLO
<< "add socket " << "add socket "
<< fd << fd
<< " to epoll_list" << " to epoll_list"
<< RESET << std::endl; << ENDL;
} }
void Server::start(void) void Server::start(void)
@@ -178,7 +175,7 @@ void Server::start(void)
{ {
ready_num = epoll_wait(_epoll_fd, _events, MAX_CLIENT, -1); ready_num = epoll_wait(_epoll_fd, _events, MAX_CLIENT, -1);
/* std::cout << TURQ << "ready_num " << ready_num << RESET << std::endl; */ /* DBOUT << TURQ << "ready_num " << ready_num << ENDL; */
if (ready_num < 0) if (ready_num < 0)
throw std::logic_error("epoll_ret"); throw std::logic_error("epoll_ret");
@@ -267,11 +264,11 @@ void Server::checkError(int fd, std::string str)
{ {
if (fd < 0) if (fd < 0)
{ {
std::cout << RED << "Server ERROR: " << str << ZERO_C << std::endl; DBOUT << RED << "Server ERROR: " << str << ENDL;
exit(1); exit(1);
} }
else else
std::cout << GREEN << "Server SUCCESS: " << str << ZERO_C << std::endl; DBOUT << GREEN << "Server SUCCESS: " << str << ENDL;
} }
Server::~Server() Server::~Server()

View File

@@ -15,7 +15,6 @@ class Server
private: private:
int _port; int _port;
int _epoll_fd; int _epoll_fd;
int _client;
struct epoll_event _events[MAX_CLIENT]; struct epoll_event _events[MAX_CLIENT];
struct sockaddr_in _addres; struct sockaddr_in _addres;
std::string _ip; std::string _ip;