Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/61/subject tester #63

Merged
merged 7 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions srcs/Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void Master::bind() {
void Master::listen() {
int ret;

ret = ::listen(listenSocket_, 2);
ret = ::listen(listenSocket_, 100000);
if (ret == -1) {
close(listenSocket_);
throw MasterException("listen: listen() failed");
Expand All @@ -64,17 +64,16 @@ void Master::listen() {

void Master::run() {
int ret;
std::vector<Worker *>::iterator itBegin = workers_.begin();
std::vector<Worker *>::iterator itEnd = workers_.end();
std::vector<Worker *>::iterator it = workers_.begin();

while (itBegin != itEnd) {
ret = (*itBegin)->work();
while (it != workers_.end()) {
ret = (*it)->work();
if (ret == FT_FALSE) {
delete *itBegin;
itBegin = workers_.erase(itBegin);
delete *it;
it = workers_.erase(it);
continue ;
}
++itBegin;
it++;
}
}

Expand Down
2 changes: 1 addition & 1 deletion srcs/Nginxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Nginxs::run() {
pollfds_[fds].fd = -1;

while (1) {
ret = poll(pollfds_, POLLFDSLEN, -1);
ret = poll(pollfds_, POLLFDSLEN, 5000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poll()에 설정한 타임아웃 시간동안 아무 이벤트가 발생하지 않으면 0을 반환하는데 이에 대한 처리도 필요해 보입니다~

Copy link
Collaborator

@hhkim0729 hhkim0729 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0을 반환한다는 것은 이벤트가 발생한 fd가 없다는 뜻이므로, 아래 masters를 순회하는 반복문 내부의 if 문 조건에 걸리지 않기 때문에 따로 예외처리를 할 필요가 없어 보입니다

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에서 잘못 설명한 부분을 정정합니다 poll() 이 하는 역할이 어떤 fd 에 이벤트가 발생할 때까지 block 하는 것이 아니라 fd가 준비될 때까지 block 하는 것인데 이때 타임아웃을 설정한다는 것의 의미는 클라이언트가 무한히 대기하지 않고 일정 시간이 지나면 에러 페이지를 반환 받을 수 있는 데에 의미가 있습니다. 만약에 반환값 0에 대한 처리를 따로 하지 않는다면 기존에 타임아웃이 무한이었던 것과 다른 점이 없지 않나요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첫 번째 의견에서 말한게 맞았네요 이벤트가 발생한 것이 없을 때 0을 반환하는게 맞는데, 이때에는 for 문을 돌면서 일일이 모든 마스터에 이벤트가 발생했는지 확인할 필요 없이 바로 continue 를 해주는 것이 효율 상 좋아보입니다.

if (ret == -1) {
for (int fds = 0; fds < POLLFDSLEN; fds++) {
if (pollfds_[fds].fd != -1)
Expand Down
2 changes: 1 addition & 1 deletion srcs/Nginxs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* : POLLFDSLEN - number of servers
*/

#define POLLFDSLEN 100
#define POLLFDSLEN 1000

class Nginxs {
private:
Expand Down
5 changes: 1 addition & 4 deletions srcs/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ ft_bool Worker::executePost() {
if (isCgi(request_->getFilePath())) {
Cgi cgi(request_);
std::string result = cgi.execute();
// std::cout << "result: " << result << std::endl;
Response response(HTTP_CREATED, stringToCharV(result), FT_TRUE);
return send(response.createMessage());
}
Expand Down Expand Up @@ -329,10 +328,8 @@ ft_bool Worker::send(const std::vector<char> &message) {
ret = ::send(pollfd_->fd, reinterpret_cast<char*>(&m[0]), m.size(), 0);
if (ret == FT_ERROR)
throw HttpException("send: send() failed", HTTP_INTERNAL_SERVER_ERROR);
if (request_->getHeaderValue("connection") == "close") {
std::cout << "connention: close" << std::endl;
if (request_->getHeaderValue("connection") == "close")
return FT_FALSE;
}
return FT_TRUE;
}

Expand Down