- 论坛徽章:
- 0
|
接收部分的代码 不知道哪里会出现问题
while(1)
{
enums = epoll_wait(epollfd, events, listenq, 20);
if (enums == -1)
{
printf("errno=%d,%s\r\n",errno,strerror(errno));
if(errno==EINTR)
{
continue;
}
perror("epoll_wait");
}
else if(enums==0)
{
continue;
}
for (n = 0; n < enums; ++n) {
listen_index=events[n].data.u32;
if (events[n].data.fd == LGWTCPSock) {
Newfd = accept(LGWTCPSock, (struct sockaddr *) &TheirAddr,&len);
if (Newfd < 0) {
perror("accept");
continue;
}
else
{
//printf("recv from: %s:%d, socket:%d enmus:%d\n", inet_ntoa(TheirAddr.sin_addr), ntohs(TheirAddr.sin_port), Newfd,enums);
}
setnonblocking(Newfd);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = Newfd;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, Newfd, &ev) < 0) {
fprintf(stderr, " socket '%d' add epoll error! %s\n",Newfd, strerror(errno));
return -1;
}
}
else if(events[n].events & EPOLLIN)
{
for(j=0;j<MAXTHREAD;j++)
{
if(0==s_thread_para[j][0]) break;
}
if(j>MAXTHREAD)
{
LOG4CPLUS_INFO(log.GetLogInstance(),"thread pool is full!\n");
close(Newfd);
continue;
}
pthread_mutex_lock(&mutex);
s_thread_para[j][0]=1;
s_thread_para[j][1]=events[n].data.fd;
pthread_mutex_unlock(&mutex);
pthread_mutex_unlock(s_mutex+j);
}
}
} |
|