[英]Odd socket() error — returns -1, but errno=ERROR_SUCCESS
I'm developing a dedicated game server on a linux machine, in C/C++ (mixed). 我正在使用C / C ++(混合)在Linux机器上开发专用的游戏服务器。 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). 我在这里的问题是套接字返回-1(表示失败)并且正在打印错误字符串,但是它是“成功”(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.
他们可能会覆盖errno值。
Are there any lines of code between socket() and if() that you left out? 您遗漏的socket()和if()之间是否有任何代码行? Another function call could overwrite the errno. 另一个函数调用可能会覆盖errno。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.