首页 新闻 赞助 找找看

急求下面关于C的代码的意思,可以把它画成流程图

0
悬赏园豆:5 [待解决问题]

void *AcceptProc(void *pCtl)
{
    int nIndex;
    int *pnCtl = NULL;
    int nNewFd;
    int nSizeOfAddr,nFlags = 0;
    DEVICEINFO st_DeviceInfo;
    struct sockaddr_in stSocketAddrClient;
    nSizeOfAddr = sizeof(struct sockaddr);
    pthread_detach(pthread_self());
    pnCtl = (int *)pCtl;
    WRITE_INFO_LOG("dmp_recv","0302010001-I","AcceptProc:"
        "a new AcceptProc is create");
    while (1)
    {
        //for thread pool mgr ,if task become litter
        //pnCtl will be set with THREAD_OUT.then ,this thread should exit
        if(*pnCtl == THREAD_OUT)
        {
            WRITE_INFO_LOG("dmp_recv","0302010002-I","AcceptProc:"
                "one AcceptProc is exit");
            pthread_exit(NULL);
        }
        pthread_mutex_lock(&g_st_canAccept.locker);
        pthread_cond_wait(&g_st_canAccept.startAble, &g_st_canAccept.locker);
        pthread_mutex_unlock(&g_st_canAccept.locker);
        //if chang this to while(1) ,do we need pthread_cond_wait anymore?
        //Can we delete the three code now?
        while(1)
        {
            //accep is a BLOCK operate
            if((nNewFd = accept(g_nListenfd, (struct sockaddr *)&stSocketAddrClient, (socklen_t *)&nSizeOfAddr)) != -1)
            {
                if(nNewFd<=0)
                {
                    WRITE_ERROR_LOG("dmp_recv","0302010003-E","AcceptProc:"
                        "new socket fd is not more than 0");
                    continue;
                }
                //nCountAccept++;
                if(fcntl(nNewFd, F_SETFL, O_NONBLOCK) != 0 )
                {
                    WRITE_ERROR_LOG("dmp_recv","0302010004-E","AcceptProc:"
                        "func error in fcntl");
                    WRITE_ERROR_LOG_EX("dmp_recv","0302010004-E-%d",nNewFd);
                    CloseFileDesc(nNewFd);
                    continue;
                }
                st_DeviceInfo.nType = nDeviceType;
                st_DeviceInfo.nSocketId = nNewFd;
                //  modify by yexiaoyu start
                //nFlags = EPOLLIN;
                nFlags = EPOLLIN | EPOLLET;
                //  modify by yexiaoyu end
                if(AddEventToEpoll(&st_DeviceInfo,nFlags) != 0)
                {
                    WRITE_ERROR_LOG("dmp_recv","0302010005-E","AcceptProc:"
                        "func error in AddEventToEpoll");
                    CloseFileDesc(nNewFd);
                    continue;
                }
                nCountAccept++;
            }
            else
            {
                AcceptErrorInfo();
                WRITE_ERROR_LOG("dmp_recv","0302010006-E","AcceptProc:"
                    "func error in accept");
            }
        }
    }
    pthread_exit(NULL);
}

周瑞娟的主页 周瑞娟 | 初学一级 | 园豆:197
提问于:2012-07-05 14:54
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册