核心代码如下
m_bRunning = true;
// first let's increase the limit of open files
int maxconn = 100000;
struct rlimit srl;
srl.rlim_cur = maxconn + 10;
srl.rlim_max = maxconn + 10;
if (setrlimit(RLIMIT_NOFILE, &srl) < 0)
{
LOG4CXX_FATAL(logger_, "Cannot set RLimit!");
exit(1);
}
epfd = epoll_create(maxconn);
if (epfd < 0)
{
LOG4CXX_FATAL(logger_, "epoll_create error!");
exit(1);
}
// Now let's ignore broken pipes
struct sigaction sa;
memset(&sa, 0, sizeof (sa));
sa.sa_handler = SIG_IGN;
if (sigaction(SIGPIPE, &sa, NULL) < 0)
{
LOG4CXX_WARN(logger_, "Error ignoring SIGPIPE!");
}
if (initSockets() < 0)
{
exit(1);
}
struct epoll_event ev, evs[MAX_EVENTS];
LOG4CXX_INFO(logger_, "Nethandler started.");
for (; ; )
{
if (!m_bRunning)
{
break;
}
int count = epoll_wait(epfd, evs, MAX_EVENTS, 10);
if (count < 0)

最低0.47元/天 解锁文章
660

被折叠的 条评论
为什么被折叠?



