winsock select() 返回值

本文详细介绍了select函数的功能与用法,该函数用于确定一个或多个套接字的状态,以便进行同步I/O操作。文章解释了各个参数的意义,如nfds、readfds、writefds等,并说明了如何设置超时时间。此外,还阐述了select函数的返回值含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O.

Syntax

int select(
  __in     int nfds,
  __inout  fd_set *readfds,
  __inout  fd_set *writefds,
  __inout  fd_set *exceptfds,
  __in     const struct timeval *timeout
);

Parameters

nfds [in]

Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.

readfds [in, out]

An optional pointer to a set of sockets to be checked for readability.

writefds [in, out]

An optional pointer to a set of sockets to be checked for writability.

exceptfds [in, out]

An optional pointer to a set of sockets to be checked for errors.

timeout [in]

The maximum time for select to wait, provided in the form of a TIMEVAL structure. Set the timeout parameter to null for blocking operations.

Return value

The select function returns the total number of socket handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to retrieve a specific error code.


1.如果超时返回 0

2.返回fd_set 中准备好的socket个数(不包括零)

3.如果没有准备好的返回 -1


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值