获得“非法搜索”调用accept()后出错
嗯..差不多就是这样,在检查我的 errno 变量时,我似乎收到了“非法查找”错误。问题是我不知道这意味着什么。
我知道套接字在 unix 中被视为文件,但我不明白这与套接字有何关系。我正在做的是:
int sck = ::accept(m_socket, (struct sockaddr*)&client_address, (socklen_t*)&address_len);
然后我得到 sck = -1 和 errno = ESPIPE
奇怪的是它是随机发生的。我的意思是,有时代码运行良好,有时只是抛出异常。我正在使用线程,所以这是可以理解的。但我只是想知道什么样的行为使得accept() 调用将 errno 设置为 ESPIPE,以便我可以检查参数。
谢谢 纳尔逊·R·佩雷斯
Well.. it's pretty much that, I seem to be getting a "Illegal Seek" error when checking my errno variable. The problem is that I have no idea of what that can mean.
I know sockets are treated like files in unix, but I can't see how can this be related to sockets. What I'm doing exactly is:
int sck = ::accept(m_socket, (struct sockaddr*)&client_address, (socklen_t*)&address_len);
Then I get sck = -1 and errno = ESPIPE
And the weird thing is that it happens randomly. I mean, sometimes the code works fine, and sometimes it just thows an exception. I'm working with threads so that's understandable. But I just would like to know what kind of behaviour makes the accept() call to set errno as ESPIPE so I could check the paramethers for instance.
Thanks
Nelson R. Pérez
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最可能的原因是
m_socket
变量已损坏。按照 @Aidan 的建议使用strace
来查看正在传递给accept(2)
的值,或者将调试器附加到进程并设置一个观察点 在该内存位置上。The most probable cause is that the
m_socket
variable is being corrupted. Usestrace
as @Aidan suggests to see what value is being passed toaccept(2)
, or attach a debugger to the process and set a watchpoint on that memory location.