开发者

Odd socket() error -- returns -1, but errno=ERROR_SUCCESS

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));
    exi开发者_StackOverflow社区t(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 am requesting a socket on a port >1024 (out of context, but thought I'd mention)
  • I'm executing the app as the super user


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜