- MMS server: fixed connection handling problem in multi-threaded mode

pull/147/head
Michael Zillgith 7 years ago
parent 4ae7a268de
commit ddb41f1cb9

@ -49,6 +49,7 @@ struct sIedServer
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore dataModelLock;
Semaphore clientConnectionsLock;
#endif
#if (CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME == 1)

@ -418,6 +418,7 @@ IedServer_createWithConfig(IedModel* dataModel, TLSConfiguration tlsConfiguratio
#if (CONFIG_MMS_THREADLESS_STACK != 1)
self->dataModelLock = Semaphore_create(1);
self->clientConnectionsLock = Semaphore_create(1);
#endif /* (CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME == 1) */
#if (CONFIG_IEC61850_REPORT_SERVICE == 1)
@ -527,6 +528,7 @@ IedServer_destroy(IedServer self)
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->dataModelLock);
Semaphore_destroy(self->clientConnectionsLock);
#endif
GLOBAL_FREEMEM(self);
@ -1471,6 +1473,10 @@ IedServer_setLogStorage(IedServer self, const char* logRef, LogStorage logStorag
ClientConnection
private_IedServer_getClientConnectionByHandle(IedServer self, void* serverConnectionHandle)
{
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_wait(self->clientConnectionsLock);
#endif
LinkedList element = LinkedList_getNext(self->clientConnections);
ClientConnection matchingConnection = NULL;
@ -1485,19 +1491,39 @@ private_IedServer_getClientConnectionByHandle(IedServer self, void* serverConnec
element = LinkedList_getNext(element);
}
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_post(self->clientConnectionsLock);
#endif
return matchingConnection;
}
void
private_IedServer_addNewClientConnection(IedServer self, ClientConnection newClientConnection)
{
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_wait(self->clientConnectionsLock);
#endif
LinkedList_add(self->clientConnections, (void*) newClientConnection);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_post(self->clientConnectionsLock);
#endif
}
void
private_IedServer_removeClientConnection(IedServer self, ClientConnection clientConnection)
{
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_wait(self->clientConnectionsLock);
#endif
LinkedList_remove(self->clientConnections, clientConnection);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_post(self->clientConnectionsLock);
#endif
}

@ -30,6 +30,9 @@
IsoConnection
IsoConnection_create(Socket socket, IsoServer isoServer);
void
IsoConnection_start(IsoConnection self);
void
IsoConnection_destroy(IsoConnection self);

@ -410,7 +410,6 @@ isoConnectionIndicationHandler(IsoConnectionIndication indication,
if (indication == ISO_CONNECTION_OPENED) {
MmsServerConnection mmsCon = MmsServerConnection_init(0, self, connection);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_wait(self->openConnectionsLock);
#endif

@ -551,11 +551,6 @@ IsoConnection_create(Socket socket, IsoServer isoServer)
#if (CONFIG_MMS_SINGLE_THREADED == 0)
#if (CONFIG_MMS_THREADLESS_STACK == 0)
self->thread = Thread_create((ThreadExecutionFunction) handleTcpConnection, self, true);
if (self->thread)
Thread_start(self->thread);
else
goto exit_error;
#endif
#endif
@ -571,6 +566,16 @@ exit_error:
return NULL;
}
void
IsoConnection_start(IsoConnection self)
{
#if (CONFIG_MMS_SINGLE_THREADED == 0)
#if (CONFIG_MMS_THREADLESS_STACK == 0)
Thread_start(self->thread);
#endif
#endif
}
void
IsoConnection_destroy(IsoConnection self)
{

@ -410,6 +410,7 @@ handleIsoConnections(IsoServer self)
self->connectionHandler(ISO_CONNECTION_OPENED, self->connectionHandlerParameter,
isoConnection);
IsoConnection_start(isoConnection);
}
}

Loading…
Cancel
Save