From c02e99a0223dd9182896954c597efa120f5be0cf Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Fri, 4 Dec 2020 10:27:20 +0100 Subject: [PATCH] - IEC 61850 client: fixed dead lock in IedConnection_getFileAsync when fileRead times out (#285) --- src/iec61850/client/ied_connection.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index fa4adb0c..a055e7af 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -1955,14 +1955,15 @@ IedConnection_getFile(IedConnection self, IedClientError* error, const char* fil return clientFileReadHandler.byteReceived; } - static void mmsConnectionFileCloseHandler (uint32_t invokeId, void* parameter, MmsError mmsError, bool success) { - (void)mmsError; (void)success; - /* TODO log error */ + if (mmsError != MMS_ERROR_NONE) { + if (DEBUG_IED_CLIENT) + printf("IED_CLIENT: failed to close file error: %i (mms-error: %i)\n", iedConnection_mapMmsErrorToIedError(mmsError), mmsError); + } IedConnection self = (IedConnection) parameter; @@ -1994,11 +1995,19 @@ mmsConnectionFileReadHandler (uint32_t invokeId, void* parameter, MmsError mmsEr handler(call->specificParameter2.getFileInfo.originalInvokeId, call->callbackParameter, err, invokeId, NULL, 0, false); - /* close file */ - call->invokeId = MmsConnection_fileCloseAsync(self->connection, &mmsError, frsmId, mmsConnectionFileCloseHandler, self); + if (mmsError != MMS_ERROR_SERVICE_TIMEOUT) { + /* close file */ + call->invokeId = MmsConnection_fileCloseAsync(self->connection, &mmsError, frsmId, mmsConnectionFileCloseHandler, self); + + if (mmsError != MMS_ERROR_NONE) + iedConnection_releaseOutstandingCall(self, call); + } + else { + if (DEBUG_IED_CLIENT) + printf("IED_CLIENT: getFile timeout -> stop download\n"); - if (mmsError != MMS_ERROR_NONE) iedConnection_releaseOutstandingCall(self, call); + } } else { bool cont = handler(call->specificParameter2.getFileInfo.originalInvokeId, call->callbackParameter, IED_ERROR_OK, invokeId, buffer, byteReceived, moreFollows);