Closed hochan222 closed 3 years ago
case 0:
ft::console_log("Timeout Reset");
int max_server_socket;
for (size_t i = 0; i < this->m_server_size; i++) {
if (max_server_socket < this->m_server[i]->get_m_server_socket())
max_server_socket = this->m_server[i]->get_m_server_socket();
}
for (int i=max_server_socket; i<=this->m_maxfd; i++)
{
if (ft::fdIsSet(i, &this->m_main_fds) || ft::fdIsSet(i, &this->m_write_fds))
{
close(i);
}
}
FD_ZERO(&this->m_main_fds);
FD_ZERO(&this->m_write_fds);
this->m_maxfd = 0;
for (size_t i = 0; i < this->m_server_size; i++) {
FD_SET(this->m_server[i]->get_m_server_socket(), &this->m_main_fds);
if (this->m_maxfd < this->m_server[i]->get_m_server_socket())
this->m_maxfd = this->m_server[i]->get_m_server_socket();
}
void
console_log(std::string str)
{
static std::string end_loop_server = "";
int fd;
std::string current_time = compareDetailTimestampToCurrent("Wed, 14 Apr 2021 15:22:00 KST");
std::string log;
log = "[" + current_time + "] " + str;
if ((fd = open("console_log", O_CREAT|O_RDWR|O_APPEND, S_IRWXU)) < 0)
throw std::exception();
ft::putendl_fd(log.c_str(), fd);
if (str == "end loop server")
{
ft::putendl_fd((current_time + " - " + end_loop_server).c_str(), fd);
end_loop_server = log;
}
std::cout << "[" << current_time << "] " << str << std::endl;
close(fd);
return ;
}
std::string
compareDetailTimestampToCurrent(std::string timestamp)
{
struct timeval current_timeval;
struct timeval timestamp_timeval;
struct tm timestamp_tm;
std::string result = "";
gettimeofday(¤t_timeval, NULL);
strptime(timestamp.c_str(), "%a, %d %b %Y %H:%M:%S %Z", ×tamp_tm);
timestamp_timeval.tv_sec = mktime(×tamp_tm);
result = std::to_string(current_timeval.tv_sec - timestamp_timeval.tv_sec);
result += std::to_string(current_timeval.tv_usec - timestamp_timeval.tv_usec);
return (result);
}
마찬가지로 따로 python이나 javascript로 tester를 만들어 돌릴때 2개이상 못돌리고 같은 현상이 일어난다. (postman도 같은현상)
다른 팀 webserv 으로 확인해본 결과 잘되는것으로보아 close 나 fd 부분을 수정해야할것같습니다.