Win32 ::shutdown() 返回 -1,但 WSAGetLastError() 返回 0?

发布于 2024-10-01 14:07:27 字数 482 浏览 5 评论 0原文

在将一些工作单元测试从 Linux 移植到 Windows 时,我遇到了一个奇怪的问题。看来,当我的测试关闭服务器套接字时, shutdown() 返回 -1,但 WSAGetLastError() 返回 0 (并且 getsockopt( with SO_ERROR ) 返回 0,并且 GetLastError() 返回 0 )...所以, shutdown( )告诉我有一个错误,但是所有查看问题所在的正常调用都返回“没问题!”...以前有人见过这个吗?

调用 shutdown 的代码如下所示:

int ret = ::shutdown( _sok, mode );
if( ret < 0 )
    X_THROW(( XSDK::ModuleId, XSDK::F_OS_ERROR, "Unable to shutdown socket."));

当我捕获异常时,我调用所有这些 GetLastError() 函数...抛出会重置最后的错误吗?

In porting some working unit tests from Linux to Windows I'm running across a strange problem. It appears that when my tests go to shutdown the server socket, shutdown() returns -1, but WSAGetLastError() returns 0 (and getsockopt( with SO_ERROR ) returns 0, and GetLastError() returns 0 )... So, shutdown() tells me there is an error, but all of the normal calls to see what that problem was are returning "no problem!"... Has anyone ever seen this before?

The code that calls shutdown looks like this:

int ret = ::shutdown( _sok, mode );
if( ret < 0 )
    X_THROW(( XSDK::ModuleId, XSDK::F_OS_ERROR, "Unable to shutdown socket."));

When I catch the exception, I call all those GetLastError() functions... Does throwing reset the last errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百善笑为先 2024-10-08 14:07:27

答案最终是几乎任何系统调用都可以清除 Win32 的“LastError()”错误...在我的例子中,抛出异常意味着格式化并记录消息,这导致错误被清除...即使我在我的 catch(...) 中立即调用 WSAGetLastError() 已经太晚了...

The answer ended up being that nearly any system calls can clear Win32's "LastError()" errors... In my case, throwing an exception meant formatting and logging a message, which caused the error to be clear... And even though I was calling WSAGetLastError() immediately in my catch(...) it was already too late...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文