示例#1
0
void test()
{
    server = epollserver_create(HTTP_PORT, MAX_CLIENT_NUM, 1024, 1024);
    printf("EAGAIN is %d\n", EAGAIN);
    printf("ECONNRESET is %d\n", ECONNRESET);
    
    server_start(server, my_logic_on_enter_pt, my_logic_on_close_pt, my_logic_on_recved_pt);
}
struct nr_mgr*
ox_create_nrmgr(
    int thread_num,
    int rbsize,
    pfn_nrmgr_check_packet check)
{
    struct nr_mgr* mgr = (struct nr_mgr*)malloc(sizeof(*mgr));

    if(mgr != NULL)
    {
        int i = 0;

        mgr->reactors = (struct net_reactor*)malloc(sizeof(struct net_reactor) * thread_num);
        mgr->reactor_num = thread_num;

        for(; i < thread_num; ++i)
        {
            struct net_reactor* reactor = mgr->reactors+i;

            reactor->mgr = mgr;
            reactor->active_num = 0;
#ifdef PLATFORM_LINUX
            reactor->server = epollserver_create(rbsize, 0, &mgr->reactors[i]);
#else
            reactor->server = iocp_create(rbsize, 0, &mgr->reactors[i]);
#endif

            reactor->free_sendmsg_list = ox_rwlist_new(DF_LIST_SIZE, sizeof(struct nrmgr_send_msg_data*), DF_RWLIST_PENDING_NUM*10);
            reactor->logic_msglist = ox_rwlist_new(DF_LIST_SIZE, sizeof(struct nrmgr_net_msg*), DF_RWLIST_PENDING_NUM);

            reactor->enter_list = ox_rwlist_new(DF_LIST_SIZE, sizeof(struct rwlist_entermsg_data), DF_RWLIST_PENDING_NUM*10);
            reactor->fromlogic_rwlist = ox_rwlist_new(1024, sizeof(struct rwlist_msg_data) , DF_RWLIST_PENDING_NUM);
            reactor->check_packet = check;

            server_start(reactor->server, reactor_logic_on_enter_callback, reactor_logic_on_disconnection_callback, reactor_logic_on_recved_callback, NULL, session_sendfinish_callback, reactor_logic_on_close_completed);
            reactor->waitsend_list = ox_stack_new(1024, sizeof(struct net_session_s*));
            reactor->waitclose_list = ox_stack_new(1024, sizeof(struct net_session_s*));
            reactor->thread = NULL;
            reactor->thread = ox_thread_new(reactor_thread, reactor);
        }
    }

    return mgr;
}