是否有必要重新选择系统调用的FD_SET? [英] Is it necessary to reset the fd_set between select system call?

查看:241
本文介绍了是否有必要重新选择系统调用的FD_SET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用在Unix中的select函数面临的一个问题。

I am facing a problem using the select function in Unix.

我有等待一个连接的服务器。首先,我监听套接字文件描述符监听器添加到使用 FD_SET(侦听FD_SET readfds , readfds)然后我用在选择()

I have a server that waits for for a connection. First I add the listening socket file descriptor listener to the fd_set readfds using FD_SET(listener, readfds) and then I use that in select().

当我得到一个方面,我称之为接受()并设置 readfds 在选择与接受的文件描述符,并开始从连接接收的数据。然而,当我检查了strace的code,则选择不显示在 readfds ,而选择()正在执行第二次。

When I get a connection, I call accept() and set the readfds in select with the accepted file descriptor and start receiving the data from connection. However, when I check the code in strace, The select doesn't show the listener in the readfds while select() is executing a second time.

我是否需要重新设置监听文件描述符使用 FD_SET(监听器,readfds)之前调用选择()一遍吗?

Do I need to set the listener file descriptor again using FD_SET(listener, readfds) before calling select() again?

感谢。

推荐答案

是的(这是需要复位 FD_SET 之间进行选择()系统调用)。

Yes (it is necessary to reset the fd_set between select() system calls).

有讨厌的,但它们作为输入/输出参数;它们被读取并由该系统调用修改。当<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html\"><$c$c>select()返回时,值都被修改,以反映该组准备的文件描述符。所以,每次你打电话之前选择(),你必须(重新)初始化 FD_SET 值。

It is a nuisance, but they act as input/output parameters; they are read by and modified by the system call. When select() returns, the values have all been modified to reflect the set of file descriptors ready. So, every time before you call select(), you have to (re)initialize the fd_set values.

这篇关于是否有必要重新选择系统调用的FD_SET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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