int Select (
int Nfds;
Fd_set far* Readfds;
Fd_set far* Writefds;
Fd_set far* Exceptfds;
const struct Timeval far* timeout;
);
#define FD_SETSIZE 64
typedef struct FD_SET
{
U_int Fd_count;
SOCKET Fd_array[fd_setsize];
}fd_set;
struct Timeval
{
Long tv_sec;
Long tv_usec;
};
FD_CLR ();//delete s socket from set set
Fd_set ();//Add the S socket to the Set collection
Fd_isset ();//Determines whether the s socket is set in set
Fd_zero ();//Initialize the set set to an empty collection
ThreadFunc (void* pparam)
{
SOCKET Slisten = ...;
Fd_set ALLFD;
Fd_set READFD;
Fd_set WRITEFD;
Fd_zero (&ALLFD);
Fd_set (Slisten, ALLFD);
while (isrunning)
{
Fd_zero (&READFD);
Fd_zero (&WRITEFD);
READFD = ALLFD;
WRITEFD = ALLFD;
int nret = SELECT (0, &READFD, &WRITEFD, NULL, NULL);
if (Nret > 0)
{
for (int i = 0; i < Allfd.fd_count; i++)
{
if (Fd_isset (Allfd.fd_array[i], &READFD))
{
if (allfd.fd_array[i] = = Slisten)
{
Accept ()
Addclient ()
Fd_set (sclient, &ALLFD);
}
else//receiving data
{
Pclient = Getclient (Allfd.fd_array[i]);
Pclient->recvdata ();
}
}
if (Fd_isset (Allfd.fd_array[i], &WRITEFD))
{
Pclient = Getclient (Allfd.fd_array[i]);
Pclient->senddata ()
}
}
}
}
}
[00020]-[2015-09-18]-[00]-[windows Socket Select model]