I am developing a C ++ DLL that needs to write some data through a (previously installed) TCP / IP connection using the write () call. To be precise, the DLL should send a bit. The 12345 process ends on 2007-09-27 15:30:42, the value i equals 131 'message on the wire when the process goes down.
Unfortunately, all the methods that I know for detecting process termination are apparently too late for any network calls. In particular, I tried the following approaches, and write () call returned -1 in each case:
- Call write () from the global object's destructor.
- Call write () from a callback function registered with atexit () .
- Call write () from DllMain (in case of argument
reason DLL_PROCESS_DETACH). I know this is unsafe, but I am a little desperate. :-)
I know that a DLL cannot detect a process stop (it could have been unloaded long before the process terminated), but since the shutdown data that the DLL should send depends on different code in the DLL, which is acceptable, I'm basically looking for the last moment when I I can safely perform network IO.
Does anyone know how to do this?
source
share