Skip to content

Commit 9dd4ba8

Browse files
committed
Fixed an endless error loop
1 parent 9675b5b commit 9dd4ba8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/CGICall.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CGICall: public CGIResponse {
6363
void execute(int, int, const std::string &);
6464
void sendError(int errorCode);
6565
void processCGIOutput();
66-
bool writePayload();
66+
bool writePayload(bool);
6767
bool writeSocket(bool);
6868
bool readPayload(bool);
6969

src/CGICall.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ CGICall::~CGICall() {
6767
pthread_join(threadID, NULL);
6868
}
6969

70-
bool CGICall::writePayload() {
70+
bool CGICall::writePayload(bool hup) {
71+
if (hup) {
72+
close(in[1]);
73+
return true;
74+
}
7175
ssize_t ret = write(in[1], _request->get_payload().c_str() + payloadCounter, _request->get_payload().size() - payloadCounter < 65536 ? _request->get_payload().size() - payloadCounter : 65536);
7276
if (ret < 0) {
7377
throw IOException("Fatal error!");
@@ -125,7 +129,7 @@ bool CGICall::writeSocket(bool hup) {
125129

126130
bool CGICall::runForFD(int fd, bool hup) {
127131
if (fd == in[1]) {
128-
return writePayload();
132+
return writePayload(hup);
129133
} else if (fd == out[0]) {
130134
return readPayload(hup);
131135
} else if (fd == socket.get_fd()) {
@@ -184,6 +188,8 @@ void CGICall::run() {
184188
fcntl(out[0], F_SETFL, O_NONBLOCK);
185189
Connection::getInstance().add_fd(out[0], this);
186190
execute(in[0], out[1], requestedFile);
191+
close(in[0]);
192+
close(out[1]);
187193
pthread_create(&threadID, NULL, reinterpret_cast<void *(*)(void *)>(CGICall::async), this);
188194
}
189195

0 commit comments

Comments
 (0)