-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Implement running multiple servers #58
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
server { | ||
listen 0.0.0.0:4242; | ||
|
||
server_name xxx.xxx.com localhost; | ||
root html; | ||
client_max_body_size 4242; | ||
|
||
error_page 400 error_pages/400.html; | ||
error_page 403 error_pages/403.html; | ||
error_page 404 error_pages/404.html; | ||
error_page 405 error_pages/405.html; | ||
error_page 500 error_pages/500.html; | ||
error_page 505 error_pages/505.html; | ||
|
||
location / { | ||
location /*.py { | ||
cgi ./cgi-bin/python-cgi.py; | ||
} | ||
index abc.html; | ||
} | ||
|
||
location /data { | ||
autoindex on; | ||
allowed_methods GET; | ||
} | ||
|
||
location /errors { | ||
} | ||
|
||
location /admin { | ||
index index.html; | ||
} | ||
} | ||
|
||
server { | ||
listen 0.0.0.0:2424; | ||
|
||
server_name xxx.xxx.com localhost; | ||
root html; | ||
client_max_body_size 4242; | ||
|
||
error_page 400 error_pages/400.html; | ||
error_page 403 error_pages/403.html; | ||
error_page 404 error_pages/404.html; | ||
error_page 405 error_pages/405.html; | ||
error_page 500 error_pages/500.html; | ||
error_page 505 error_pages/505.html; | ||
|
||
location / { | ||
location /*.py { | ||
cgi ./cgi-bin/python-cgi.py; | ||
} | ||
index abc.html; | ||
} | ||
|
||
location /data { | ||
autoindex on; | ||
allowed_methods GET; | ||
} | ||
|
||
location /errors { | ||
} | ||
|
||
location /admin { | ||
index index.html; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "Nginxs.hpp" | ||
|
||
Nginxs::Nginxs() {} | ||
|
||
Nginxs::Nginxs(const char *confFilePath) { | ||
config_.parseConfigFile(confFilePath); | ||
} | ||
|
||
Nginxs::~Nginxs() { | ||
std::vector<Master *>::iterator masterIt; | ||
|
||
for (masterIt = masters_.begin(); masterIt != masters_.end(); masterIt++) | ||
delete *masterIt; | ||
} | ||
|
||
void Nginxs::run() { | ||
std::size_t i = 0; | ||
int ret; | ||
|
||
std::vector<Block> serverBlocks = config_.getServerBlocks(); | ||
std::vector<Block>::iterator it; | ||
std::vector<Master *>::iterator masterIt; | ||
|
||
for (it = serverBlocks.begin(); it != serverBlocks.end(); it++) | ||
{ | ||
Master *m = new Master(*it); | ||
m->setPollIndex(i); | ||
std::cout << "setPollIndex: " << i << std::endl; | ||
masters_.push_back(m); | ||
|
||
pollfds_[i].fd = m->getListenSocket(); | ||
pollfds_[i].events = POLLIN | POLLOUT; | ||
pollfds_[i].revents = 0; | ||
i++; | ||
} | ||
|
||
// Initialize pollfds for workers | ||
for (int fds = i; fds < POLLFDSLEN; fds++) | ||
pollfds_[fds].fd = -1; | ||
|
||
while (1) { | ||
ret = poll(pollfds_, POLLFDSLEN, -1); | ||
if (ret == -1) { | ||
for (int fds = 0; fds < POLLFDSLEN; fds++) { | ||
if (pollfds_[fds].fd != -1) | ||
close(pollfds_[fds].fd); | ||
} | ||
throw std::runtime_error("run: poll() failed"); | ||
} | ||
for(masterIt = masters_.begin(); masterIt != masters_.end(); masterIt++) { | ||
if (pollfds_[(*masterIt)->getPollIndex()].revents & POLLIN) { | ||
struct pollfd *emptyPollFd = findEmptyPollfd(); | ||
// // if (emptyPollFd == nullptr) | ||
// // throw 503 | ||
// std::cout << "master: " << masterIt->getPollIndex() << std::endl; | ||
(*masterIt)->appendWorker(emptyPollFd); | ||
} | ||
(*masterIt)->run(); | ||
} | ||
} | ||
for (int fds = 0; fds < POLLFDSLEN; fds++) { | ||
if (pollfds_[fds].fd != -1) | ||
close(pollfds_[fds].fd); | ||
} | ||
} | ||
|
||
struct pollfd *Nginxs::findEmptyPollfd() | ||
{ | ||
for (int i = 0; i < POLLFDSLEN; i++) { | ||
if (pollfds_[i].fd == -1) { | ||
std::cout << "pollfd index: " << i << std::endl; | ||
return &pollfds_[i]; | ||
} | ||
} | ||
return nullptr; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분에서 leak 문제 없을까요? for문으로 사용할 수 없을지 검색해보다가, 포인터 배열 다루다가 메모리 누수 많이 난다고 봐서요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 찾았습니다... for문으로 바꾸는 게 깔끔할 것 같아요~! 저거 작성할 때는 저희가 이터레이터 쓰는 방법을 잘 모를 때 저렇게 작성했던 것 같습니다. 이전에 Master에 있던 코드 그대로입니다..
누수는 추후에 리팩토링 하면서 다시 확인해봐야 할 것 같습니다.