Files
open62541/examples/server_mainloop.c
Andreas Ebner 16a739a7c3 fix(server): fail startup when no transport can open a server socket
UA_Server_run_startup ignored the driver results and ran without
listening. It now fails if a transport cannot open its socket and
neither another transport nor a reverse connect reaches the server.
2026-10-13 08:55:20 +02:00

43 lines
1.2 KiB
C

/*
* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
*/
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
#include <signal.h>
#include <stdlib.h>
static volatile UA_Boolean running = true;
static void stopHandler(int sign) {
(void)sign;
running = false;
}
/* In this example, we integrate the server into an external "mainloop". This
* can be for example the event-loop used in GUI toolkits, such as Qt or GTK. */
int main(int argc, char** argv) {
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);
UA_Server *server = UA_Server_new();
UA_StatusCode retval = UA_Server_run_startup(server);
if(retval != UA_STATUSCODE_GOOD) {
UA_Server_delete(server);
return EXIT_FAILURE;
}
/* Should the server networklayer block (with a timeout) until a message
arrives or should it return immediately? */
UA_Boolean waitInternal = true;
while(running) {
UA_Server_run_iterate(server, waitInternal);
}
UA_Server_run_shutdown(server);
UA_Server_delete(server);
return 0;
}