12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include <open62541/plugin/log_stdout.h>
- #include <open62541/server.h>
- #include <open62541/server_config_default.h>
- #include <signal.h>
- #include <stdlib.h>
- UA_Boolean running = true;
- static void stopHandler(int sign) {
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
- running = false;
- }
- int main(int argc, char** argv) {
- signal(SIGINT, stopHandler);
- signal(SIGTERM, stopHandler);
- UA_Server *server = UA_Server_new();
- UA_ServerConfig_setDefault(UA_Server_getConfig(server));
-
- UA_Boolean waitInternal = false;
- UA_StatusCode retval = UA_Server_run_startup(server);
- if(retval != UA_STATUSCODE_GOOD)
- goto cleanup;
- while(running) {
-
-
- UA_UInt16 timeout = UA_Server_run_iterate(server, waitInternal);
-
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = timeout * 1000;
- select(0, NULL, NULL, NULL, &tv);
- }
- retval = UA_Server_run_shutdown(server);
- cleanup:
- UA_Server_delete(server);
- return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
- }
|