I'm currently trying to break out of the wait for accept() and/or write() by using signals, in this case SIGINT. My the program doesn't leave either as expected.
void sigHandler(int signal ){
printf(" Exit\n");
//x is global
x = 1;
return;
}
My snipped from main I'm getting hung up on is mainly:
clientfd = accept( sockfd, (struct sockaddr *) &client_addr, (unsigned int *) &client_addr_len );
When I hit this and use my signal and return, I'm still stuck on this line of code, waiting for a user to connect to my socket. The x in the handler is to for the outer loop this piece of code is in.
Is there a better way to do what I'm trying to do? Also, let me know if this isn't enough information.
Thank you.
Edit:
Here is the check for the signal, which is back at the top of main. I think this is what you were asking for:
if ( signal( SIGINT, signalhandler ) == SIG_ERR ){
return( 1 );
}