gpt4 book ai didi

c - 选择()在C : the Rosetta stone?

转载 作者:太空宇宙 更新时间:2023-11-03 23:31:04 25 4
gpt4 key购买 nike

主要是select()就设置哪些标志而言很简单:

  • r 如果数据可读,
  • 如果它是可写的,
  • e 用于套接字紧急数据

但是这条规则有很多异常(exception)(或者,也许是重要的扩展):'w' 设置为已完成的非阻塞连接,'r' 设置为 listen()带有待处理的 accept(),等等。

有没有人找到在什么情况下设置哪些标志的简单列表?

最佳答案

来自 this reference page :

A descriptor shall be considered ready for reading when a call to an input function with O_NONBLOCK clear would not block, whether or not the function would transfer data successfully. (The function might return data, an end-of-file indication, or an error other than one indicating that it is blocked, and in each of these cases the descriptor shall be considered ready for reading.)

A descriptor shall be considered ready for writing when a call to an output function with O_NONBLOCK clear would not block, whether or not the function would transfer data successfully.

If a socket has a pending error, it shall be considered to have an exceptional condition pending. Otherwise, what constitutes an exceptional condition is file type-specific.

除了异常集中的描述符外,其他都非常清楚。如果阻塞描述符(无论它是文件、套接字还是其他描述符)不会阻塞,那么它在各自的集合中被标记为就绪。接受和接收是“读”操作,而连接和写是“写”操作。

唯一有问题的是异常状态,这取决于您在集合中传递的描述符类型。

关于c - 选择()在C : the Rosetta stone?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15499819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com