summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@jp.adit-jv.com>2015-12-01 11:11:51 +0900
committerLutz Helwing <lutz_helwing@mentor.com>2015-12-16 10:41:36 +0100
commitc4f073db44a36cfa96a17032afedbf36e4afc3b6 (patch)
tree97be20ed225465770e06eafa83e39a5089e8d531
parentf54b52d764a7ea0f4c80e6124f5d89d3968d2906 (diff)
downloadDLT-daemon-c4f073db44a36cfa96a17032afedbf36e4afc3b6.tar.gz
MultiNode: Reconnection after connection loss
The Gateway DLT Daemon will try to reconnect to a passive node once after the connection was lost. The maximum number of reconnects can be configured by changing the DLT_GATEWAY_RECONNECT_MAX definition. Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com>
-rw-r--r--src/gateway/dlt_gateway.c28
-rw-r--r--src/gateway/dlt_gateway_types.h3
2 files changed, 22 insertions, 9 deletions
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index a7d7d39..27626ee 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -634,6 +634,8 @@ int dlt_gateway_establish_connections(DltGateway *gateway,
{
/* connection to passive node established, add to event loop */
con->status = DLT_GATEWAY_CONNECTED;
+ con->reconnect_cnt = 0;
+ con->timeout_cnt = 0;
/* setup dlt connection and add to epoll event loop here */
if (dlt_connection_create(daemon_local,
@@ -745,17 +747,25 @@ int dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
return -1;
}
- con->status = DLT_GATEWAY_DISCONNECTED;
- if (dlt_event_handler_unregister_connection(&daemon_local->pEvent,
- daemon_local,
- receiver->fd,
- DLT_CONNECTION_GATEWAY) != 0)
- {
- dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
- }
-
dlt_log(LOG_WARNING, "Connection to passive node lost\n");
+ if (con->reconnect_cnt < DLT_GATEWAY_RECONNECT_MAX)
+ {
+ dlt_log(LOG_WARNING, "Try to reconnect.\n");
+ con->reconnect_cnt += 1;
+ con->timeout_cnt = 0;
+ }
+ else
+ {
+ con->status = DLT_GATEWAY_DISCONNECTED;
+ if (dlt_event_handler_unregister_connection(&daemon_local->pEvent,
+ daemon_local,
+ receiver->fd,
+ DLT_CONNECTION_GATEWAY) != 0)
+ {
+ dlt_log(LOG_ERR, "Remove passive node Connection failed\n");
+ }
+ }
return 0;
}
diff --git a/src/gateway/dlt_gateway_types.h b/src/gateway/dlt_gateway_types.h
index b1247dd..ad841c1 100644
--- a/src/gateway/dlt_gateway_types.h
+++ b/src/gateway/dlt_gateway_types.h
@@ -63,6 +63,8 @@
#define DLT_GATEWAY_CONFIG_PATH CONFIGURATION_FILES_DIR "/dlt_gateway.conf"
#define DLT_GATEWAY_TIMER_INTERVAL 1
+#define DLT_GATEWAY_RECONNECT_MAX 1 /* reconnect once after connection loss */
+
typedef enum
{
DLT_GATEWAY_UNINITIALIZED,
@@ -92,6 +94,7 @@ typedef struct {
connection_trigger trigger; /* connection trigger */
int timeout; /* connection timeout */
int timeout_cnt; /* connection timeout counter */
+ int reconnect_cnt; /* reconnection counter */
DltClient client; /* DltClient structure */
} DltGatewayConnection;