简体   繁体   English

奇怪的socket()错误-返回-1,但errno = ERROR_SUCCESS

[英]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 am requesting a socket on a port >1024 (out of context, but thought I'd mention) 我正在请求端口> 1024上的套接字(出于上下文,但我以为提到了)
  • 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. 他们可能会覆盖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.

相关问题 SymEnumSymbols返回ERROR_SUCCESS但没有结果 - SymEnumSymbols returns ERROR_SUCCESS but gives no results CreateWindowEx函数失败,但GetLastError()返回ERROR_SUCCESS - CreateWindowEx function fails but GetLastError() returns ERROR_SUCCESS RegOpenKeyEx 返回 ERROR_SUCCESS 但 RegSetValueEx 总是返回 ERROR_ACCESS_DENIED - RegOpenKeyEx returns ERROR_SUCCESS but RegSetValueEx allways returns ERROR_ACCESS_DENIED FindWindowA() 返回 0,当我使用 GetLastError() 检查错误代码时,它也是 0 (ERROR_SUCCESS) - FindWindowA() returns 0 and when i check the error code with GetLastError() it's also 0 (ERROR_SUCCESS) RegQueryValueEx返回ERROR_SUCCESS,但没有获取数据缓冲区。 为什么? - RegQueryValueEx returns ERROR_SUCCESS but it does not get me the data buffer. Why? CreateDirectory 报告失败但错误代码为 ERROR_SUCCESS - CreateDirectory reports that it failed but the error code is ERROR_SUCCESS RegOpenKeyEx返回ERROR_SUCCESS,但不应返回(Windows 7) - RegOpenKeyEx return ERROR_SUCCESS but it shouldn't (windows 7) 我的 RegSetValueA function 返回 ERROR_SUCCESS 但不工作 - My RegSetValueA function is returning ERROR_SUCCESS but not working RegQueryValueEx - 向此函数添加什么代码以显示ERROR_SUCCESS - RegQueryValueEx - What code add to this function to show ERROR_SUCCESS 如果没有错误发生,哪个WinAPI函数将最后一个错误设置为ERROR_SUCCESS? - Which WinAPI function set last error to ERROR_SUCCESS if no error occured?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM