Server wrapper: SOPC_ServerHelper_StopServer waits synchronously when used afer StartServer
Description
SOPC_ServerHelper_StopServer now waits synchronously the server is actually stopped when using SOPC_ServerHelper_StartServer API to start the server. Thus it is not necessary anymore for applicative code to wait for the stopped callback (provided to StartServer) to be called before calling SOPC_ServerConfigHelper_Clear.
When SOPC_ServerHelper_Serve is used the behavior is unchanged: SOPC_ServerHelper_Serve is blocking until server is actually stopped whereas SOPC_ServerHelper_StopServer is not.
Code version identification
V1.6.0 (ba0ba8a1)
Current behavior
SOPC_ServerHelper_StopServer API is not robust and not practical.
Moreover some memory leak will happen in case of premature server stop (typically: Endpoint port not available, or any event but not due to call to SOPC_ServerHelper_StopServer)
First step to enforce that stopped state is reached prior to clear operation was implemented in #1275 (closed). But is still application code responsibility to actually wait for all EPs to be closed using closed event received through dedicated callback.
The current behavior is correct regarding the StopServer API documentation but it seems it should be changed to avoid giving responsibility to user application to wait for a callback call:
If server started with ::SOPC_ServerHelper_StartServer, this call is blocking during shutdown phase and ::SOPC_ServerStopped_Fct is called on actual shutdown. Caller is responsible to wait for ::SOPC_ServerStopped_Fct call prior to use any ::SOPC_ServerConfigHelper_Clear function.
Moreover, concerning the "premature server stop", The documentation of SOPC_ServerHelper_StartServer is unclear because it states that:
- User must call
SOPC_ServerHelper_StopServerafter thestoppedCbwas called. - The
stoppedCbis automatically called by the toolkit in case of premature stop. Therefore, the user cannot callSOPC_ServerHelper_StopServer, which leads to memory leak, beacuse some resources are not released (e.g.SOPC_UpdateCurrentTime_EventHandler_Callbacktimer)
Expected behavior
- The
SOPC_ServerHelper_StopServershould wait synchronously for those events to avoid user application code to implement it. - In the case of "premature server stop" manage correctly memory, call to StopServer is unnecessary and will fail.
Security impact
None
Implementation
- In case of in case of
StartServecase, reuse the existing synchronous server stop mechanism forServeto be used in theStopServerfunction directly - Reserve the
stoppedCb(renameuserStoppedCb) to applicative callback and always use the internal callback that manage syncrhonous stop - Reset the synchronous server stop data in case of Init/Clear/Start
- Cancel/Clear the UpdateCurrentTime timer when server is stopped to manage well resources in case of premature stop