2010年(30)
分类: C/C++
2010-07-26 11:28:21
socket()
...
bind()
...
listen(listen_fd, x)
...
conn_fd = accept()
struct pollfd client[MAX];
int conn_fd;
client[0].fd = listen_fd;
client[0].events = POLLIN;
for(;;)
{
poll();
if(client[0].revents & POLLIN)
{
/*New client connection */
conn_fd = accept();
for(i = 0; i < MAX; i++)
{
if(client[i].fd < 0){
client[i].fd = conn_fd;
client[i].event = POLLIN;
}
}
for(i = 1;i < MAX; i++)
{
if(client[i].fd < 0) continue;
if(client[i].revents &(POLLRONORM | POLLERR))
{
read();
write();
}
...
}