|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
/*
|
|
|
|
|
* iso_server.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2013-2018 Michael Zillgith
|
|
|
|
|
* Copyright 2013-2020 Michael Zillgith
|
|
|
|
|
*
|
|
|
|
|
* This file is part of libIEC61850.
|
|
|
|
|
*
|
|
|
|
@ -66,6 +66,8 @@ struct sIsoServer {
|
|
|
|
|
Thread serverThread;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HandleSet handleset;
|
|
|
|
|
|
|
|
|
|
Socket serverSocket;
|
|
|
|
|
int tcpPort;
|
|
|
|
|
const char* localIpAddress;
|
|
|
|
@ -147,7 +149,7 @@ addClientConnection(IsoServer self, IsoConnection connection)
|
|
|
|
|
|
|
|
|
|
self->connectionCounter++;
|
|
|
|
|
if (DEBUG_ISO_SERVER)
|
|
|
|
|
printf("IsoServer: increase connection counter to %i!\n", self->connectionCounter);
|
|
|
|
|
printf("ISO_SERVER: increase connection counter to %i!\n", self->connectionCounter);
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
lockClientConnections(self);
|
|
|
|
@ -183,11 +185,6 @@ addClientConnection(IsoServer self, IsoConnection connection)
|
|
|
|
|
static void
|
|
|
|
|
removeClientConnection(IsoServer self, IsoConnection connection)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
lockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -205,6 +202,10 @@ removeClientConnection(IsoServer self, IsoConnection connection)
|
|
|
|
|
for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) {
|
|
|
|
|
if (self->openClientConnections[i] == connection) {
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_SINGLE_THREADED == 1)
|
|
|
|
|
IsoConnection_removeFromHandleSet(connection, self->handleset);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (DEBUG_ISO_SERVER)
|
|
|
|
|
printf("ISO_SERVER: removed connection (%p) index:%i\n", connection, i);
|
|
|
|
|
|
|
|
|
@ -213,10 +214,72 @@ removeClientConnection(IsoServer self, IsoConnection connection)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
removeTerminatedConnections(IsoServer self, bool isSingleThread)
|
|
|
|
|
{
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
lockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1)
|
|
|
|
|
|
|
|
|
|
LinkedList openConnection = LinkedList_getNext(self->openClientConnections);
|
|
|
|
|
while (openConnection != NULL) {
|
|
|
|
|
IsoConnection isoConnection = (IsoConnection) openConnection->data;
|
|
|
|
|
|
|
|
|
|
if (isSingleThread) {
|
|
|
|
|
if (IsoConnection_getState(isoConnection) == ISO_CON_STATE_STOPPED) {
|
|
|
|
|
|
|
|
|
|
self->connectionHandler(ISO_CONNECTION_CLOSED, self->connectionHandlerParameter,
|
|
|
|
|
isoConnection);
|
|
|
|
|
|
|
|
|
|
IsoConnection_close(isoConnection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsoConnection_getState(isoConnection) == ISO_CON_STATE_TERMINATED) {
|
|
|
|
|
removeClientConnection(self, isoConnection);
|
|
|
|
|
IsoConnection_destroy(isoConnection);
|
|
|
|
|
openConnection = LinkedList_getNext(self->openClientConnections);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
openConnection = LinkedList_getNext(openConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) {
|
|
|
|
|
if (self->openClientConnections[i] != NULL) {
|
|
|
|
|
|
|
|
|
|
IsoConnection isoConnection = self->openClientConnections[i];
|
|
|
|
|
|
|
|
|
|
if (isSingleThread) {
|
|
|
|
|
if (IsoConnection_getState(isoConnection) == ISO_CON_STATE_STOPPED) {
|
|
|
|
|
|
|
|
|
|
self->connectionHandler(ISO_CONNECTION_CLOSED, self->connectionHandlerParameter,
|
|
|
|
|
isoConnection);
|
|
|
|
|
|
|
|
|
|
IsoConnection_close(isoConnection);
|
|
|
|
|
|
|
|
|
|
IsoConnection_removeFromHandleSet(isoConnection, self->handleset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsoConnection_getState(isoConnection) == ISO_CON_STATE_TERMINATED) {
|
|
|
|
|
removeClientConnection(self, isoConnection);
|
|
|
|
|
IsoConnection_destroy(isoConnection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
unlockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -234,11 +297,7 @@ closeAllOpenClientConnections(IsoServer self)
|
|
|
|
|
IsoConnection isoConnection = (IsoConnection) openConnection->data;
|
|
|
|
|
|
|
|
|
|
IsoConnection_close(isoConnection);
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_SINGLE_THREADED == 1)
|
|
|
|
|
/* if CONFIG_MMS_SINGLE_THREADED == 0 connection instance will be destroyed by connection thread. */
|
|
|
|
|
IsoConnection_destroy(isoConnection);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
openConnection = LinkedList_getNext(openConnection);
|
|
|
|
|
}
|
|
|
|
@ -253,14 +312,43 @@ closeAllOpenClientConnections(IsoServer self)
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) {
|
|
|
|
|
if (self->openClientConnections[i] != NULL) {
|
|
|
|
|
|
|
|
|
|
IsoConnection_close(self->openClientConnections[i]);
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_SINGLE_THREADED == 1)
|
|
|
|
|
/* if CONFIG_MMS_SINGLE_THREADED == 0 connection instance will be destroyed by connection thread. */
|
|
|
|
|
IsoConnection_destroy(self->openClientConnections[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
unlockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
callTickHandlerForClientConnections(IsoServer self)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
lockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1)
|
|
|
|
|
|
|
|
|
|
LinkedList openConnection = LinkedList_getNext(self->openClientConnections);
|
|
|
|
|
while (openConnection != NULL) {
|
|
|
|
|
IsoConnection isoConnection = (IsoConnection) openConnection->data;
|
|
|
|
|
|
|
|
|
|
IsoConnection_callTickHandler(isoConnection);
|
|
|
|
|
|
|
|
|
|
openConnection = LinkedList_getNext(openConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) {
|
|
|
|
|
if (self->openClientConnections[i] != NULL) {
|
|
|
|
|
IsoConnection_callTickHandler(self->openClientConnections[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */
|
|
|
|
@ -287,7 +375,7 @@ handleClientConnections(IsoServer self)
|
|
|
|
|
IsoConnection isoConnection = (IsoConnection) openConnection->data;
|
|
|
|
|
|
|
|
|
|
if (IsoConnection_isRunning(isoConnection))
|
|
|
|
|
IsoConnection_handleTcpConnection(isoConnection);
|
|
|
|
|
IsoConnection_handleTcpConnection(isoConnection, true);
|
|
|
|
|
else {
|
|
|
|
|
IsoConnection_destroy(isoConnection);
|
|
|
|
|
|
|
|
|
@ -315,7 +403,7 @@ handleClientConnections(IsoServer self)
|
|
|
|
|
if (self->openClientConnections[i] != NULL) {
|
|
|
|
|
if (IsoConnection_isRunning(self->openClientConnections[i])) {
|
|
|
|
|
|
|
|
|
|
IsoConnection_handleTcpConnection(self->openClientConnections[i]);
|
|
|
|
|
IsoConnection_handleTcpConnection(self->openClientConnections[i], true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
IsoConnection_destroy(self->openClientConnections[i]);
|
|
|
|
@ -330,6 +418,8 @@ handleClientConnections(IsoServer self)
|
|
|
|
|
unlockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
removeTerminatedConnections(self, true);
|
|
|
|
|
|
|
|
|
|
#endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -347,6 +437,9 @@ setupIsoServer(IsoServer self)
|
|
|
|
|
goto exit_function;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self->handleset = Handleset_new();
|
|
|
|
|
Handleset_addSocket(self->handleset, self->serverSocket);
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_ACTIVATE_TCP_KEEPALIVE == 1)
|
|
|
|
|
Socket_activateTcpKeepAlive(self->serverSocket,
|
|
|
|
|
CONFIG_TCP_KEEPALIVE_IDLE,
|
|
|
|
@ -365,67 +458,24 @@ exit_function:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK == 0)
|
|
|
|
|
/* used by single and multi-threaded versions */
|
|
|
|
|
/** used by single and multi-threaded versions
|
|
|
|
|
*
|
|
|
|
|
* \param isSingleThread when true server is running in single thread or non-thread mode
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
handleIsoConnections(IsoServer self)
|
|
|
|
|
{
|
|
|
|
|
Socket connectionSocket;
|
|
|
|
|
|
|
|
|
|
if ((connectionSocket = ServerSocket_accept((ServerSocket) self->serverSocket)) != NULL) {
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME == 1)
|
|
|
|
|
if (self->maxConnections > -1) {
|
|
|
|
|
if (private_IsoServer_getConnectionCounter(self) >= self->maxConnections) {
|
|
|
|
|
if (DEBUG_ISO_SERVER)
|
|
|
|
|
printf("ISO_SERVER: maximum number of connections reached -> reject connection attempt.\n");
|
|
|
|
|
|
|
|
|
|
Socket_destroy(connectionSocket);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME == 1) */
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS != -1)
|
|
|
|
|
if (private_IsoServer_getConnectionCounter(self) >= CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS) {
|
|
|
|
|
if (DEBUG_ISO_SERVER)
|
|
|
|
|
printf("ISO_SERVER: maximum number of connections reached -> reject connection attempt.\n");
|
|
|
|
|
|
|
|
|
|
Socket_destroy(connectionSocket);
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_SINGLE_THREADED == 1)
|
|
|
|
|
handleClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
IsoConnection isoConnection = IsoConnection_create(connectionSocket, self);
|
|
|
|
|
|
|
|
|
|
if (isoConnection) {
|
|
|
|
|
|
|
|
|
|
addClientConnection(self, isoConnection);
|
|
|
|
|
|
|
|
|
|
self->connectionHandler(ISO_CONNECTION_OPENED, self->connectionHandlerParameter,
|
|
|
|
|
isoConnection);
|
|
|
|
|
|
|
|
|
|
IsoConnection_start(isoConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleIsoConnections(IsoServer self, bool isSingleThread)
|
|
|
|
|
{
|
|
|
|
|
if (isSingleThread) {
|
|
|
|
|
/*
|
|
|
|
|
* NOTE: when running in multi thread mode the tick handler is called
|
|
|
|
|
* by the connection thread.
|
|
|
|
|
*/
|
|
|
|
|
callTickHandlerForClientConnections(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_SINGLE_THREADED == 1)
|
|
|
|
|
handleClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MMS_THREADLESS_STACK == 0) */
|
|
|
|
|
if (Handleset_waitReady(self->handleset, 1) < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* used by non-threaded version */
|
|
|
|
|
static void
|
|
|
|
|
handleIsoConnectionsThreadless(IsoServer self)
|
|
|
|
|
{
|
|
|
|
|
Socket connectionSocket;
|
|
|
|
|
|
|
|
|
|
if ((connectionSocket = ServerSocket_accept((ServerSocket) self->serverSocket)) != NULL) {
|
|
|
|
@ -450,28 +500,35 @@ handleIsoConnectionsThreadless(IsoServer self)
|
|
|
|
|
|
|
|
|
|
Socket_destroy(connectionSocket);
|
|
|
|
|
|
|
|
|
|
handleClientConnections(self);
|
|
|
|
|
if (isSingleThread)
|
|
|
|
|
handleClientConnections(self);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
IsoConnection isoConnection = IsoConnection_create(connectionSocket, self);
|
|
|
|
|
IsoConnection isoConnection = IsoConnection_create(connectionSocket, self, isSingleThread);
|
|
|
|
|
|
|
|
|
|
if (isoConnection) {
|
|
|
|
|
|
|
|
|
|
addClientConnection(self, isoConnection);
|
|
|
|
|
|
|
|
|
|
if (isSingleThread)
|
|
|
|
|
IsoConnection_addToHandleSet(isoConnection, self->handleset);
|
|
|
|
|
|
|
|
|
|
self->connectionHandler(ISO_CONNECTION_OPENED, self->connectionHandlerParameter,
|
|
|
|
|
isoConnection);
|
|
|
|
|
|
|
|
|
|
if (isSingleThread == false)
|
|
|
|
|
IsoConnection_start(isoConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleClientConnections(self);
|
|
|
|
|
if (isSingleThread)
|
|
|
|
|
handleClientConnections(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
|
#if (CONFIG_MMS_SINGLE_THREADED == 0) && (CONFIG_MMS_THREADLESS_STACK == 0)
|
|
|
|
|
/* only required for multi-threaded server! */
|
|
|
|
|
static void
|
|
|
|
|
isoServerThread(void* isoServerParam)
|
|
|
|
@ -490,9 +547,9 @@ isoServerThread(void* isoServerParam)
|
|
|
|
|
|
|
|
|
|
while (self->state == ISO_SVR_STATE_RUNNING)
|
|
|
|
|
{
|
|
|
|
|
handleIsoConnections(self);
|
|
|
|
|
removeTerminatedConnections(self, false);
|
|
|
|
|
|
|
|
|
|
Thread_sleep(1);
|
|
|
|
|
handleIsoConnections(self, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self->state = ISO_SVR_STATE_STOPPED;
|
|
|
|
@ -501,8 +558,7 @@ isoServerThread(void* isoServerParam)
|
|
|
|
|
self->serverSocket = NULL;
|
|
|
|
|
|
|
|
|
|
if (DEBUG_ISO_SERVER)
|
|
|
|
|
printf("ISO_SERVER: isoServerThread %p stopped\n", &isoServerParam);
|
|
|
|
|
|
|
|
|
|
printf("ISO_SERVER: isoServerThread %p stopped\n", &isoServerParam);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -593,7 +649,7 @@ IsoServer_getTLSConfiguration(IsoServer self)
|
|
|
|
|
return self->tlsConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED != 1)
|
|
|
|
|
void
|
|
|
|
|
IsoServer_startListening(IsoServer self)
|
|
|
|
|
{
|
|
|
|
@ -620,7 +676,7 @@ IsoServer_startListening(IsoServer self)
|
|
|
|
|
exit_function:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif /* (CONFIG_MMS_THREADLESS_STACK != 1) */
|
|
|
|
|
#endif /* (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED != 1) */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
IsoServer_startListeningThreadless(IsoServer self)
|
|
|
|
@ -645,66 +701,15 @@ IsoServer_waitReady(IsoServer self, unsigned int timeoutMs)
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
if (getState(self) == ISO_SVR_STATE_RUNNING) {
|
|
|
|
|
HandleSet handles = Handleset_new();
|
|
|
|
|
|
|
|
|
|
if (handles) {
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
lockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1)
|
|
|
|
|
|
|
|
|
|
LinkedList openConnection = LinkedList_getNext(self->openClientConnections);
|
|
|
|
|
LinkedList lastConnection = self->openClientConnections;
|
|
|
|
|
|
|
|
|
|
while (openConnection != NULL) {
|
|
|
|
|
IsoConnection isoConnection = (IsoConnection) openConnection->data;
|
|
|
|
|
|
|
|
|
|
if (IsoConnection_isRunning(isoConnection)) {
|
|
|
|
|
IsoConnection_addToHandleSet(isoConnection, handles);
|
|
|
|
|
openConnection = LinkedList_getNext(openConnection);
|
|
|
|
|
} else {
|
|
|
|
|
#if ((CONFIG_MMS_SINGLE_THREADED == 1) || (CONFIG_MMS_THREADLESS_STACK == 1))
|
|
|
|
|
IsoConnection_destroy(isoConnection);
|
|
|
|
|
#endif
|
|
|
|
|
lastConnection->next = openConnection->next;
|
|
|
|
|
GLOBAL_FREEMEM(openConnection);
|
|
|
|
|
openConnection = lastConnection->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastConnection = lastConnection->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) {
|
|
|
|
|
if (self->openClientConnections[i] != NULL) {
|
|
|
|
|
if (IsoConnection_isRunning(self->openClientConnections[i])) {
|
|
|
|
|
IsoConnection_addToHandleSet(self->openClientConnections[i], handles);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#if ((CONFIG_MMS_SINGLE_THREADED == 1) || (CONFIG_MMS_THREADLESS_STACK == 1))
|
|
|
|
|
IsoConnection_destroy(self->openClientConnections[i]);
|
|
|
|
|
#endif
|
|
|
|
|
self->openClientConnections[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1) && (CONFIG_MMS_SINGLE_THREADED == 0)
|
|
|
|
|
unlockClientConnections(self);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Handleset_addSocket(handles, self->serverSocket);
|
|
|
|
|
result = Handleset_waitReady(handles, timeoutMs);
|
|
|
|
|
Handleset_destroy(handles);
|
|
|
|
|
} else {
|
|
|
|
|
result = -1;
|
|
|
|
|
if (self->handleset) {
|
|
|
|
|
result = Handleset_waitReady(self->handleset, 10);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (DEBUG_ISO_SERVER)
|
|
|
|
|
printf("ISO_SERVER: internal error - no handleset!\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
result = -1;
|
|
|
|
|
}
|
|
|
|
@ -712,12 +717,17 @@ IsoServer_waitReady(IsoServer self, unsigned int timeoutMs)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
IsoServer_processIncomingMessages(IsoServer self)
|
|
|
|
|
{
|
|
|
|
|
if (getState(self) == ISO_SVR_STATE_RUNNING)
|
|
|
|
|
handleIsoConnectionsThreadless(self);
|
|
|
|
|
handleIsoConnections(self, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
IsoServer_getConnectionCounter(IsoServer self)
|
|
|
|
|
{
|
|
|
|
|
return private_IsoServer_getConnectionCounter(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -769,8 +779,6 @@ IsoServer_closeConnection(IsoServer self, IsoConnection isoConnection)
|
|
|
|
|
self->connectionHandler(ISO_CONNECTION_CLOSED, self->connectionHandlerParameter,
|
|
|
|
|
isoConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeClientConnection(self, isoConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -811,6 +819,9 @@ IsoServer_destroy(IsoServer self)
|
|
|
|
|
Semaphore_destroy(self->openClientConnectionsMutex);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (self->handleset)
|
|
|
|
|
Handleset_destroy(self->handleset);
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
|
Semaphore_destroy(self->stateLock);
|
|
|
|
|
#endif
|
|
|
|
|