I'm developing a dedicated game server on a linux machine, in C/C++ (mixed). I have the following snippet of code:
int sockfd=socket(AI_INET, SOCK_DGRAM, 0);
if(sockfd==-1)
{
int err=errno;
fprintf(stderr,"%s",strerror(err));
exit(1);
}
My problem here, is that socket is returning -1 (implying a failure) and the error string is being printed, but it is "Success" (ERROR_SUCCESS).
Other notes:
I feel incredibly stupid. Carefully looking over my code, on my dev-computer shows:
if(sockfd==-1);
...
Do you have multiple threads running?
They could be overwriting the errno value.
Are there any lines of code between socket() and if() that you left out? Another function call could overwrite the errno.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.