Commit 84a36ddd authored by Krzysztof Kliś's avatar Krzysztof Kliś Committed by GitHub

Merge pull request #4 from ticpu/more_fixes

Correct possible hangs.
parents f532b9ae 62da2709
......@@ -190,7 +190,6 @@ void update_connection_count()
/* Handle finished child process */
void sigchld_handler(int signal) {
while (waitpid(-1, NULL, WNOHANG) > 0);
update_connection_count();
}
/* Handle term signal */
......@@ -266,9 +265,9 @@ void forward_data(int source_sock, int destination_sock) {
exit(EXIT_FAILURE);
}
while ((n = splice(source_sock, NULL, buf_pipe[WRITE], NULL, BUF_SIZE, SPLICE_F_MOVE)) > 0) {
if (splice(buf_pipe[READ], NULL, destination_sock, NULL, n, SPLICE_F_MOVE) < 0) {
perror("splice");
while ((n = splice(source_sock, NULL, buf_pipe[WRITE], NULL, SSIZE_MAX, SPLICE_F_NONBLOCK|SPLICE_F_MOVE)) > 0) {
if (splice(buf_pipe[READ], NULL, destination_sock, NULL, SSIZE_MAX, SPLICE_F_MOVE) < 0) {
perror("write");
exit(EXIT_FAILURE);
}
}
......@@ -280,6 +279,9 @@ void forward_data(int source_sock, int destination_sock) {
}
#endif
if (n < 0)
perror("read");
#ifdef USE_SPLICE
close(buf_pipe[0]);
close(buf_pipe[1]);
......@@ -357,3 +359,4 @@ int create_connection() {
return sock;
}
/* vim: set et ts=4 sw=4: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment