diff --git a/src/mms/inc/mms_client_connection.h b/src/mms/inc/mms_client_connection.h index 838d24d..0f28b6a 100644 --- a/src/mms/inc/mms_client_connection.h +++ b/src/mms/inc/mms_client_connection.h @@ -188,10 +188,10 @@ MmsConnection_close(MmsConnection self); /** * \brief Uses the MMS/ACSE abort service to close the connection to the server * - * This service should be used to abruptly interrupt the connection to the server. The TCP connection will - * be closed immediately after sending the ACSE abort message to the server. It is not quite clear what the + * This service should be used to abruptly interrupt the connection to the server. It is not quite clear what the * benefit of this service is (simply closing the TCP connection should do the same). Though it is required by - * conformance tests. + * conformance tests. In case the server doesn't close the connection after the internal timeout interval the + * client will close the TCP connection and set mmsError to MMS_ERROR_SERVICE_TIMEOUT. * * \param self MmsConnection instance to operate on * \param mmsError user provided variable to store error code diff --git a/src/mms/inc_private/iso_client_connection.h b/src/mms/inc_private/iso_client_connection.h index d593866..2c6fae3 100644 --- a/src/mms/inc_private/iso_client_connection.h +++ b/src/mms/inc_private/iso_client_connection.h @@ -67,7 +67,12 @@ IsoClientConnection_sendMessage(IsoClientConnection self, ByteBuffer* payload); void IsoClientConnection_release(IsoClientConnection self); -void +/** + * \brief Send ACSE abort message and wait until connection is closed by server or timeout occured + * + * \return true if abort has been successful, false indicates a timeout + */ +bool IsoClientConnection_abort(IsoClientConnection self); void diff --git a/src/mms/iso_client/iso_client_connection.c b/src/mms/iso_client/iso_client_connection.c index b279f08..159d14f 100644 --- a/src/mms/iso_client/iso_client_connection.c +++ b/src/mms/iso_client/iso_client_connection.c @@ -498,7 +498,7 @@ IsoClientConnection_destroy(IsoClientConnection self) GLOBAL_FREEMEM(self); } -void +bool IsoClientConnection_abort(IsoClientConnection self) { //TODO block other messages from being sent @@ -535,6 +535,11 @@ IsoClientConnection_abort(IsoClientConnection self) uint64_t timeout = Hal_getTimeInMs() + CONFIG_TCP_READ_TIMEOUT_MS; while ((self->handlingThreadRunning == true) && (Hal_getTimeInMs() < timeout)); + + if (self->handlingThreadRunning) + return false; + else + return true; } void diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index 0e5e91b..43997b8 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -925,10 +925,15 @@ MmsConnection_abort(MmsConnection self, MmsError* mmsError) self->connectionLostHandler = NULL; - if (self->associationState == MMS_STATE_CONNECTED) - IsoClientConnection_abort(self->isoClient); + bool success = true; - //TODO wait for connection to be closed + if (self->associationState == MMS_STATE_CONNECTED) + success = IsoClientConnection_abort(self->isoClient); + + if (success == false) { + IsoClientConnection_close(self->isoClient); + *mmsError = MMS_ERROR_SERVICE_TIMEOUT; + } } static void