- some code cleanup in mms_client_connection.c

pull/21/head
Michael Zillgith 8 years ago
parent 291d21ef9e
commit 311c70ea30

@ -285,11 +285,9 @@ sendRequestAndWaitForResponse(MmsConnection self, uint32_t invokeId, ByteBuffer*
{ {
ByteBuffer* receivedMessage = NULL; ByteBuffer* receivedMessage = NULL;
uint64_t startTime = Hal_getTimeInMs(); uint64_t currentTime = Hal_getTimeInMs();
uint64_t waitUntilTime = startTime + self->requestTimeout;
uint64_t currentTime = startTime; uint64_t waitUntilTime = currentTime + self->requestTimeout;
bool success = false; bool success = false;
@ -311,15 +309,20 @@ sendRequestAndWaitForResponse(MmsConnection self, uint32_t invokeId, ByteBuffer*
goto connection_lost; goto connection_lost;
Semaphore_wait(self->lastResponseLock); Semaphore_wait(self->lastResponseLock);
receivedInvokeId = self->responseInvokeId; receivedInvokeId = self->responseInvokeId;
Semaphore_post(self->lastResponseLock);
if (receivedInvokeId == invokeId) { if (receivedInvokeId == invokeId) {
receivedMessage = self->lastResponse; receivedMessage = self->lastResponse;
Semaphore_post(self->lastResponseLock);
success = true; success = true;
break; break;
} }
Semaphore_post(self->lastResponseLock);
Thread_sleep(10); Thread_sleep(10);
currentTime = Hal_getTimeInMs(); currentTime = Hal_getTimeInMs();
@ -662,7 +665,7 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
self->concludeState = CONCLUDE_STATE_REQUESTED; self->concludeState = CONCLUDE_STATE_REQUESTED;
/* TODO block all new user requests */ /* TODO block all new user requests? */
IsoClientConnection_releaseReceiveBuffer(self->isoClient); IsoClientConnection_releaseReceiveBuffer(self->isoClient);
} }
@ -697,6 +700,7 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
else { else {
if (checkForOutstandingCall(self, invokeId)) { if (checkForOutstandingCall(self, invokeId)) {
/* wait for application thread to handle last received response */
waitUntilLastResponseHasBeenProcessed(self); waitUntilLastResponseHasBeenProcessed(self);
Semaphore_wait(self->lastResponseLock); Semaphore_wait(self->lastResponseLock);
@ -1047,11 +1051,9 @@ MmsConnection_getMmsConnectionParameters(MmsConnection self)
static void static void
waitForConnectResponse(MmsConnection self) waitForConnectResponse(MmsConnection self)
{ {
uint64_t startTime = Hal_getTimeInMs(); uint64_t currentTime = Hal_getTimeInMs();
uint64_t waitUntilTime = startTime + self->requestTimeout; uint64_t waitUntilTime = currentTime + self->requestTimeout;
uint64_t currentTime = startTime;
while (currentTime < waitUntilTime) { while (currentTime < waitUntilTime) {
if (self->connectionState != MMS_CON_WAITING) if (self->connectionState != MMS_CON_WAITING)
@ -1061,7 +1063,6 @@ waitForConnectResponse(MmsConnection self)
currentTime = Hal_getTimeInMs(); currentTime = Hal_getTimeInMs();
} }
} }
bool bool

Loading…
Cancel
Save