From 5ed474a44a1611b548a28f99742fd0d378572c6f Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 6 Dec 2018 14:10:04 +0100 Subject: [PATCH] - MMS client: fixed problem with async connect timeout --- src/iec61850/client/ied_connection.c | 3 --- src/mms/iso_client/iso_client_connection.c | 29 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index 2e90d8ad..e8766229 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -640,8 +640,6 @@ IedConnection_connect(IedConnection self, IedClientError* error, const char* hos MmsError mmsError; - MmsConnection_setConnectionLostHandler(self->connection, NULL, NULL); - MmsConnection_setConnectTimeout(self->connection, self->connectionTimeout); if (MmsConnection_connect(self->connection, &mmsError, hostname, tcpPort)) { @@ -672,7 +670,6 @@ IedConnection_connectAsync(IedConnection self, IedClientError* error, const char MmsError mmsError = MMS_ERROR_NONE; MmsConnection_setConnectTimeout(self->connection, self->connectionTimeout); - MmsConnection_setConnectionLostHandler(self->connection, NULL, NULL); MmsConnection_connectAsync(self->connection, &mmsError, hostname, tcpPort); diff --git a/src/mms/iso_client/iso_client_connection.c b/src/mms/iso_client/iso_client_connection.c index dbe320bf..3acfdce7 100644 --- a/src/mms/iso_client/iso_client_connection.c +++ b/src/mms/iso_client/iso_client_connection.c @@ -77,7 +77,7 @@ struct sIsoClientConnection volatile int state; Semaphore stateMutex; - uint64_t nextReadTimeout; + uint64_t nextReadTimeout; /* timeout value for read and connect */ Socket socket; @@ -335,7 +335,20 @@ IsoClientConnection_handleConnection(IsoClientConnection self) nextState = INT_STATE_CLOSE_ON_ERROR; } else { - waits = true; + + /* check connect timeout */ + + uint64_t currentTime = Hal_getTimeInMs(); + + if (currentTime > self->nextReadTimeout) { + IsoClientConnection_releaseTransmitBuffer(self); + self->callback(ISO_IND_ASSOCIATION_FAILED, self->callbackParameter, NULL); + nextState = INT_STATE_CLOSE_ON_ERROR; + } + else { + waits = true; + } + } } @@ -599,6 +612,13 @@ IsoClientConnection_handleConnection(IsoClientConnection self) } break; + default: + + if (DEBUG_ISO_CLIENT) + printf("ISO_CLIENT_CONNECTION: Illegal state\n"); + + break; + } self->callback(ISO_IND_TICK, self->callbackParameter, NULL); @@ -623,8 +643,6 @@ IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTim self->socket = TcpSocket_create(); - Socket_setConnectTimeout(self->socket, connectTimeoutInMs); - #if (CONFIG_ACTIVATE_TCP_KEEPALIVE == 1) Socket_activateTcpKeepAlive(self->socket, CONFIG_TCP_KEEPALIVE_IDLE, @@ -634,6 +652,9 @@ IsoClientConnection_associateAsync(IsoClientConnection self, uint32_t connectTim setIntState(self, INT_STATE_TCP_CONNECTING); + /* set timeout for connect */ + self->nextReadTimeout = Hal_getTimeInMs() + connectTimeoutInMs; + if (Socket_connectAsync(self->socket, self->parameters->hostname, self->parameters->tcpPort) == false) { Socket_destroy(self->socket);