Win32 ::shutdown() 返回 -1,但 WSAGetLastError() 返回 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案最终是几乎任何系统调用都可以清除 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...