[PLUG] Closing sockets using atexit C code.

michael michael at robinson-west.com
Tue Nov 14 18:26:45 UTC 2017


In C there is an atexit function that takes no arguments.  Because of 
this, you can't pass in the
file descriptors for your sockets.  Uge!  Short of making these integers 
global, how can I close
these sockets on premature program termination?

int client=0,server=0;

void exiting()
{
     close(client);
     close(server);
}

int main(void)
{
     atexit(exiting);

     struct sockaddr...
}

Note that there are a bunch of includes for TCP sockets and a lot more 
code.



More information about the PLUG mailing list