如何将 TCP 套接字更改为非阻塞? [英] How do I change a TCP socket to be non-blocking?

查看:27
本文介绍了如何将 TCP 套接字更改为非阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使套接字无阻塞?

我知道 fcntl() 函数,但我听说它并不总是可靠的.

I am aware of the fcntl() function, but I've heard it's not always reliable.

推荐答案

不总是可靠的"是什么意思?如果系统成功地将您的套接字设置为非阻塞,它将是非阻塞的.套接字操作将返回 EWOULDBLOCK 如果它们需要阻塞(例如,如果输出缓冲区已满并且您经常调用发送/写入).

What do you mean by "not always reliable"? If the system succeeds in setting your socket non non-blocking, it will be non-blocking. Socket operations will return EWOULDBLOCK if they would block need to block (e.g. if the output buffer is full and you're calling send/write too often).

这个论坛主题在处理非阻塞调用时有几个优点.

This forum thread has a few good points when working with non-blocking calls.

这篇关于如何将 TCP 套接字更改为非阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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