问题描述
可能的重复:
在 Win32 中,是有没有办法测试套接字是否是非阻塞的?
这就是我在 Windows 中将套接字设置为非阻塞模式的方式.
无符号长模式 = is_blocking ?0 : 1;int ret = ::ioctlsocket(m_Socket, FIONBIO, &mode);
在我的复杂库中,我偶尔会收到锁,因为传递给它的某些套接字未设置为非阻塞模式.所以,我想添加和断言能够看到非阻塞套接字是从哪里传递的.问题是我不知道如何测试套接字是否阻塞.
在 unix 上,很简单:
long arg = 0;if((arg = fcntl(m_Socket, F_GETFL, NULL))
那么,我如何测试套接字是否在 Windows 上阻塞.谢谢
解决方案Windows 不提供任何方式来查询套接字当前设置为阻塞还是非阻塞.
This is how I set socket to non-blocking mode in windows.
unsigned long mode = is_blocking ? 0 : 1; int ret = ::ioctlsocket(m_Socket, FIONBIO, &mode);
In my complex library I'm getting occasional locks because some sockets passed to it weren't set to non-blocking mode. So, I would like to add and assert to be able to see where non-blocking socket is passed from. The problem is that I have no idea how to test if socket is blocking or not.
On unix, it's simple:long arg = 0; if((arg = fcntl(m_Socket, F_GETFL, NULL)) < 0) { return ERROR; } bool was_blocking = (arg & O_NONBLOCK) != 0;
so, how can I test if socket is blocking on windows.thanks
解决方案Windows does not offer any way to query whether a socket is currently set to blocking or non-blocking.
这篇关于检查套接字是否阻塞(特定于 Winsock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!