在阅读swoole源码中发现,在src/reactor/ReactorEpoll.c 的 swReactorEpoll_create 创建reactor线程的时候指定了最大事件个数是512个,但是配置中swoole_config.h中的默认 SW_REACTOR_MAXEVENTS 值是 4096, 求解答
int swReactorEpoll_create(swReactor *reactor, int max_event_num)
{
//create reactor object
swReactorEpoll *reactor_object = sw_malloc(sizeof(swReactorEpoll));
if (reactor_object == NULL)
{
swWarn("malloc[0] failed.");
return SW_ERR;
}
bzero(reactor_object, sizeof(swReactorEpoll));
reactor->object = reactor_object;
reactor->max_event_num = max_event_num;
reactor_object->events = sw_calloc(max_event_num, sizeof(struct epoll_event));
if (reactor_object->events == NULL)
{
swWarn("malloc[1] failed.");
sw_free(reactor_object);
return SW_ERR;
}
//epoll create
reactor_object->epfd = epoll_create(512); // 疑问就在这一行
if (reactor_object->epfd < 0)
{
swWarn("epoll_create failed. Error: %s[%d]", strerror(errno), errno);
sw_free(reactor_object);
return SW_ERR;
}
//binding method
reactor->add = swReactorEpoll_add;
reactor->set = swReactorEpoll_set;
reactor->del = swReactorEpoll_del;
reactor->wait = swReactorEpoll_wait;
reactor->free = swReactorEpoll_free;
return SW_OK;
}
网友评论