When a server program exits, it should notify the DSOM run time that it is no longer accepting requests. This should be done whether the program exits normally, or as the result of an error. If this is not done, somdd will continue to think that the server program is active, allowing clients to attempt to connect to it, as well as preventing a new copy of that server from being activated.
To notify DSOM when the server program is exiting, the deactivate_impl method defined on SOMOA should be called. For example,
/* tell DSOM (via SOMOA) that server is now terminating */ _deactivate_impl(SOMD_SOMOAObject, &ev, SOMD_ImplDefObject);
Note: For robustness, it would be worthwhile to add appropriate "exit handlers" or "signal handlers" to your application servers that call the deactivate_impl method upon abnormal program termination. This ensures the the DSOM daemon is made aware of the server's termination, so that client connections are no longer allowed.
Finally, at the end of a server program, the SOMD_Uninit procedure must be called to free DSOM run-time objects, and to release semaphores, shared memory segments, and any other system resources.
For example, the exit code in the server program might look like this:
... SOMD_Uninit(&e); SOM_UninitEnvironment(&e); }
Observe also the SOM_UninitEnvironment call, which frees any memory associated with the specified Environment structure.
When a Windows DSOM server application receives a WM_QUIT message while processing incoming requests, the execute_request_loop method will return SOMDERROR_WMQUIT. When the server receives SOMDERROR_WMQUIT, it should perform its usual clean up and termination procedures.