Commit 7c6b3b00 authored by jerome.poulin's avatar jerome.poulin Committed by Jérôme Poulin

First call to splice should not block while writing to pipe.

In certain condition, if the second call to splice does not write a full
packet, the first call to splice can block since the pipe is full, to prevent
this condition, we never block while writing to the pipe.
parent 8444d3c0
...@@ -265,9 +265,9 @@ void forward_data(int source_sock, int destination_sock) { ...@@ -265,9 +265,9 @@ void forward_data(int source_sock, int destination_sock) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while ((n = splice(source_sock, NULL, buf_pipe[WRITE], NULL, BUF_SIZE, SPLICE_F_MOVE)) > 0) { 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, n, SPLICE_F_MOVE) < 0) { if (splice(buf_pipe[READ], NULL, destination_sock, NULL, SSIZE_MAX, SPLICE_F_MOVE) < 0) {
perror("splice"); perror("write");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
...@@ -279,6 +279,9 @@ void forward_data(int source_sock, int destination_sock) { ...@@ -279,6 +279,9 @@ void forward_data(int source_sock, int destination_sock) {
} }
#endif #endif
if (n < 0)
perror("read");
#ifdef USE_SPLICE #ifdef USE_SPLICE
close(buf_pipe[0]); close(buf_pipe[0]);
close(buf_pipe[1]); close(buf_pipe[1]);
......
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