Message-ID: <4BPhd6$wLr@bbs.sdu.edu.cn>
Subject: The select Model(3)
Date: Sun, 28 Mar 2004 11:43:18 +0000
From: onek.bbs@bbs.sdu.edu.cn (�式�)
Path: news.cnusenet.org!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-cn.bbs.comp.lang.mbox.zip!archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!nntp.giganews.com!ngpeer.news.aol.com!feed2.newsreader.com!newsreader.com!maily.cic.tsinghua.edu.cn!netnews.sdu.edu.cn!SDU
Newsgroups: cn.bbs.comp.lang
Organization: 泉������
X-Filename: Programming/M.1080474198.A
Xref: news.cnusenet.org cn.bbs.comp.lang:18071
For example, when you want to test a socket for readability, you must add it t
o the readfds set and wait for the select function to complete. When the selec
t call completes, you have to determine if your socket is still part of the re
adfds set. If so, the socket is readable��you can begin to retrieve data from
it. Any two of the three parameters (readfds, writefds, exceptfds) can be null
values (at least one must not be null), and any non-null set must contain at
least one socket handle; otherwise, the select function won't have anything to
wait for. The final parameter, timeout, is a pointer to a timeval structure t
hat determines how long the select function will wait for I/O to complete. If
timeout is a null pointer, select will block indefinitely until at least one d
escriptor meets the specified criteria. The timeval structure is defined as
struct timeval
{
long tv_sec;
long tv_usec;
};
The tv_sec field indicates how long to wait in seconds; the tv_usec field indi
cates how long to wait in milliseconds. The timeout value {0, 0} indicates sel
ect will return immediately, allowing an application to poll on the select ope
ration. This should be avoided for performance reasons. When select completes
successfully, it returns the total number of socket handles that have I/O oper
ations pending in the fd_set structures. If the timeval limit expires, it retu
rns 0. If select fails for any reason, it returns SOCKET_ERROR.
--
[0;1;33m�� ��源:��泉������ http://bbs.sdu.edu.cn [FROM: 202.194.32.132][m