检查套接字是否阻塞(特定于 Winsock) [英] Check is socket is blocking (Winsock specific)

查看:32
本文介绍了检查套接字是否阻塞(特定于 Winsock)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

可能的重复:
在 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)) <0) {返回错误;}bool was_blocking = (arg & O_NONBLOCK) != 0;



那么,我如何测试套接字是否在 Windows 上阻塞.

谢谢

解决方案

Windows 不提供任何方式来查询套接字当前设置为阻塞还是非阻塞.

Possible Duplicate:
In Win32, is there a way to test if a socket is non-blocking?

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆