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

pull/179/head
Michael Zillgith 7 years ago
parent 95cf87ebb4
commit c98a2b0baa

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

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

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

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

@ -93,7 +93,7 @@ static void
finalizeIsoConnection(IsoConnection self) finalizeIsoConnection(IsoConnection self)
{ {
if (DEBUG_ISO_SERVER) if (DEBUG_ISO_SERVER)
printf("ISO_SERVER: finalizeIsoConnection --> close transport connection\n"); printf("ISO_SERVER: finalizeIsoConnection (%p)--> close transport connection\n", self);
IsoServer_closeConnection(self->isoServer, self); IsoServer_closeConnection(self->isoServer, self);
@ -515,14 +515,22 @@ IsoConnection_create(Socket socket, IsoServer isoServer)
#if (CONFIG_MMS_SINGLE_THREADED == 0) #if (CONFIG_MMS_SINGLE_THREADED == 0)
#if (CONFIG_MMS_THREADLESS_STACK == 0) #if (CONFIG_MMS_THREADLESS_STACK == 0)
self->thread = Thread_create((ThreadExecutionFunction) handleTcpConnection, self, true); self->thread = Thread_create((ThreadExecutionFunction) handleTcpConnection, self, true);
Thread_start(self->thread);
#endif #endif
#endif #endif
return self; return self;
} }
void
IsoConnection_start(IsoConnection self)
{
#if (CONFIG_MMS_SINGLE_THREADED == 0)
#if (CONFIG_MMS_THREADLESS_STACK == 0)
Thread_start(self->thread);
#endif
#endif
}
void void
IsoConnection_destroy(IsoConnection self) IsoConnection_destroy(IsoConnection self)
{ {

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

Loading…
Cancel
Save