From d5ec52ef7880a0db802a4be9f05621789d893640 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 11 Jan 2022 00:25:31 +0100 Subject: [PATCH] - mms client: improved locking for outstanding calls --- .../iso_mms/client/mms_client_connection.c | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index d7eacfd0..cdbbb2b2 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -1008,23 +1008,31 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) int i = 0; - Semaphore_wait(self->outstandingCallsLock); - for (i = 0; i < OUTSTANDING_CALLS; i++) { + + Semaphore_wait(self->outstandingCallsLock); + if (self->outstandingCalls[i].isUsed) { + + Semaphore_post(self->outstandingCallsLock); + if (currentTime > self->outstandingCalls[i].timeout) { if (self->outstandingCalls[i].type != MMS_CALL_TYPE_NONE) handleAsyncResponse(self, NULL, 0, &(self->outstandingCalls[i]), MMS_ERROR_SERVICE_TIMEOUT); + Semaphore_wait(self->outstandingCallsLock); + self->outstandingCalls[i].isUsed = false; - break; + + Semaphore_post(self->outstandingCallsLock); } } + else { + Semaphore_post(self->outstandingCallsLock); + } } - Semaphore_post(self->outstandingCallsLock); - if (self->concludeHandler) { if (currentTime > self->concludeTimeout) { self->concludeHandler(self->concludeHandlerParameter, MMS_ERROR_SERVICE_TIMEOUT, false); @@ -1045,25 +1053,30 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload) if (self->connectionLostHandler != NULL) self->connectionLostHandler(self, self->connectionLostHandlerParameter); - /* Cleanup outstanding calls */ { int i; for (i = 0; i < OUTSTANDING_CALLS; i++) { + + Semaphore_wait(self->outstandingCallsLock); + if (self->outstandingCalls[i].isUsed) { + Semaphore_post(self->outstandingCallsLock); + if (self->outstandingCalls[i].type != MMS_CALL_TYPE_NONE) handleAsyncResponse(self, NULL, 0, &(self->outstandingCalls[i]), MMS_ERROR_SERVICE_TIMEOUT); + Semaphore_wait(self->outstandingCallsLock); + self->outstandingCalls[i].isUsed = false; - break; } + + Semaphore_post(self->outstandingCallsLock); } } - Semaphore_post(self->outstandingCallsLock); - return true; }