aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-20 17:23:06 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-06-20 17:23:06 +0200
commit976c68a13f71568f7bf6d00dbf6a308cfe1008ba (patch)
tree3ebec6959b45d12163f2c918277157f84707d899
parenteef1934af8e38f91fb96ca922f6f52fa7d8d2a9a (diff)
downloadlimiter-976c68a13f71568f7bf6d00dbf6a308cfe1008ba.zip
limiter-976c68a13f71568f7bf6d00dbf6a308cfe1008ba.tar.bz2
Prevents filter from continuing with no data read.
-rw-r--r--src/filter/filter.c12
-rw-r--r--src/server/server_types.h3
-rw-r--r--src/server/server_worker.c44
3 files changed, 57 insertions, 2 deletions
diff --git a/src/filter/filter.c b/src/filter/filter.c
index 20adb79..f5132e2 100644
--- a/src/filter/filter.c
+++ b/src/filter/filter.c
@@ -121,6 +121,10 @@ static int listen_to_upstream
return -1;
}
+ else if (io_bytes == 0)
+ {
+ return 1;
+ }
errno = old_errno;
@@ -226,6 +230,10 @@ static int send_downstream
return -1;
}
+ else if (io_bytes == 0)
+ {
+ return 1;
+ }
errno = 0;
@@ -296,6 +304,10 @@ static int send_upstream
return -1;
}
+ else if (io_bytes == 0)
+ {
+ return 1;
+ }
errno = 0;
diff --git a/src/server/server_types.h b/src/server/server_types.h
index f43e47d..aae3b9d 100644
--- a/src/server/server_types.h
+++ b/src/server/server_types.h
@@ -19,6 +19,9 @@
#define JH_SERVER_SOCKET_ACCEPT_TIMEOUT_SEC 5
#define JH_SERVER_SOCKET_LISTEN_BACKLOG 5
+#define JH_SERVER_WORKER_MAX_RETRIES 5
+#define JH_SERVER_WORKER_RETRY_DELAY_SEC 1
+
enum JH_server_thread_state
{
JH_SERVER_JOINING_THREAD,
diff --git a/src/server/server_worker.c b/src/server/server_worker.c
index 12387a7..583f0b4 100644
--- a/src/server/server_worker.c
+++ b/src/server/server_worker.c
@@ -47,9 +47,13 @@ void * JH_server_worker_main (void * input)
{
struct JH_limiter_filter filter;
struct JH_server_worker worker;
+ int retries;
+ int state;
initialize(&worker, input);
+ retries = 0;
+
if (JH_limiter_filter_initialize(&filter, worker.params.socket) < 0)
{
finalize(&worker);
@@ -59,9 +63,45 @@ void * JH_server_worker_main (void * input)
while (JH_server_is_running())
{
- if (JH_limiter_filter_step(&filter, worker.params.server_params) < 0)
+ state = JH_limiter_filter_step(&filter, worker.params.server_params);
+
+ switch (state)
{
- break;
+ case 0:
+ retries = 0;
+ break;
+
+ case 1:
+ retries += 1;
+
+ if (retries == JH_SERVER_WORKER_MAX_RETRIES)
+ {
+ JH_S_ERROR
+ (
+ stderr,
+ "Thread's upstream socket timed out too many consequent"
+ " times."
+ );
+
+ JH_limiter_filter_finalize(&filter);
+
+ finalize(&worker);
+
+ return NULL;
+
+ }
+ else
+ {
+ sleep(JH_SERVER_WORKER_RETRY_DELAY_SEC);
+ }
+ break;
+
+ default:
+ JH_limiter_filter_finalize(&filter);
+
+ finalize(&worker);
+
+ return NULL;
}
}