- 论坛徽章:
- 0
|
遇到了一个奇怪的问题,我起了100线程,同时连接服务端,客户端显示都连接成功(connect 没有报错),可是服务端检测到有60~90的连接数,有时候能检测到100个连接
我的监听端结构如下:难道这个结构有问题?? 谢谢指点
SOCKET = CreateSocket();
BindSocket();
ListenSocket();
int epoll_fd, actfd;
struct epoll_event ev, events[10000];
epoll_fd = epoll_create( 10000 );
ev.data.fd = SOCKET;
ev.events = EPOLLIN|EPOLLET;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, SOCKET, &ev);
int curfds = 1;
while(1)
{
actfd = epoll_wait(epoll_fd, events, curfds, 1);// 1 毫秒
for (i = 0; i < actfd; ++i)
{
if (events.data.fd == SOCKET)
{
if ((AcceptFd = AcceptSocket()) == -1)
{
continue;
}
//将AcceptFd 加入到 list 队列中去
ev.data.fd = AcceptFd;
ev.events = EPOLLERR|EPOLLPRI|EPOLLIN|EPOLLET;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, AcceptFd, &ev);
curfds ++
}
else if(events.events&EPOLLIN)
{
if (MyIOCtl(events.data.fd) == 0)//触发可读事件但IO里没有数据,认为是客户端关闭
{
close(events.data.fd);
curfds --;
continue;
}
//Socket 加入 到 list 里并通知接收
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, events.data.fd, &ev);// epoll事件集合中删除
}
if (events.events&EPOLLERR)
{
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, events.data.fd, &ev);
close(events.data.fd);
curfds --;
}
}
} //end while
[ 本帖最后由 liujq110 于 2009-4-17 22:17 编辑 ] |
|