美文网首页
swoole ReactorEpoll.c 最大事件个数

swoole ReactorEpoll.c 最大事件个数

作者: cc180912 | 来源:发表于2018-11-15 19:37 被阅读6次

在阅读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;
}

相关文章

网友评论

      本文标题:swoole ReactorEpoll.c 最大事件个数

      本文链接:https://www.haomeiwen.com/subject/nllufqtx.html