Here is what I have so far
socklen_t cli_size;
struct sockaddr cli;
int in_sock;
/* event from TCP server socket, new connection */
cli_size = sizeof(cli);
try {
if ((in_sock = ::accept(handle,&cli, &cli_size)) < 0) {
throw in_sock;
return NULL;
}
}
catch(int ex) {
cout << "Exception Nr. " << ex << endl;
}
from man page:
On error, -1 is returned, and errno is set appropriately.
Question: I still can’t understand where is errno? I need to understand exception
errnois a global integer variable that contains error codes after system calls likeacceptfails. You might have to include the header file<errno.h>for the variable to be defined.In your case, you shouldn’t throw the value returned by
acceptbut the value oferrno:The function
std::strerroris declared in the header file<cstring>and returns a string describing the error.An important note: The value of
errnois only valid if a function returns that it failed. If, in your example,acceptsucceeds then the value oferrnois undefined.