From c4f073db44a36cfa96a17032afedbf36e4afc3b6 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Tue, 1 Dec 2015 11:11:51 +0900 Subject: 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 --- src/gateway/dlt_gateway.c | 28 +++++++++++++++++++--------- src/gateway/dlt_gateway_types.h | 3 +++ 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; -- cgit v1.2.1