Ejemplo n.º 1
0
void OSEventThread::firePending()
{
    TRACE("~~~~ +firePending ~~~~\n");
    event_req_t * ev;
    while (ev = UT_LIST_GET_FIRST(mPendingList)) {
        UT_LIST_REMOVE(activeNode,mPendingList,ev);
        try
        {
			ev->func(ev->fd, OSEventContext::EV_RE, ev->param); 
            ev->status = 0;
        }
        catch (...) {
            ERR("Falut req = %p\n",ev);
            ASSERT_C(0);
        }
    }

    event_timer_t * tev;
    while (tev = UT_LIST_GET_FIRST(mTimeoutList)) {
        UT_LIST_REMOVE(activeNode,mTimeoutList,tev);
        try
        {
            tev->func(tev->timeout, tev->param); 
            tev->status = 0;
        }
        catch (...) {
            ERR("Falut timer = %p\n",tev);
            ASSERT_C(0);
        }
    }

    TRACE("~~~~ -firePending ~~~~\n");
}
Ejemplo n.º 2
0
bool JSON_Type2Type(const Json::Value &subNode, std::string &value)
{
	if (Json::stringValue == subNode.type())
	{
		value = subNode.asString();
		return true;
	}
	ASSERT_C(false);
	return false;
}
Ejemplo n.º 3
0
bool JSON_Type2Type(const Json::Value &subNode, int &value)
{
	if (Json::intValue == subNode.type())
	{
		value = subNode.asInt();
		return true;
	}
	ASSERT_C(false);
	return false;
}
Ejemplo n.º 4
0
void OSEventThread::Entry()
{
    int n;
    fd_set rfds;
    struct timeval tv;
    struct timeval * ptv = NULL;

    ULONG lasttime = OS::GetTickCount();
    ULONG currtime = lasttime;

    init_wakeuper();

    while (!IsStopRequested()) {

        //10 check time rollback
        lasttime = currtime;
        currtime = OS::GetTickCount();
        if(currtime < lasttime) {
            rollback_timer(currtime);
            firePending();
        }

        //20 calc timeout
        if (-1 == calcNextTimeout(&tv,currtime)) {
            // no pending timers; block indefinitely
            TRACE("~~~~ no timers; blocking indefinitely ~~~~\n");
            ptv = NULL;
        } else {
            TRACE("~~~~ blocking for %ds + %dus ~~~~\n", (int)tv.tv_sec, (int)tv.tv_usec);
            ptv = &tv;
        }

        //30 make local copy of read fd_set
        memcpy(&rfds, &mReadFds, sizeof(fd_set));

        //40 select
        n = select(mMaxfFd, &rfds, NULL, NULL, ptv);

        TRACE("~~~~ %d events fired ~~~~\n", n);
        
        if(n > 0){

            //50 Check for read-ready
            processReadReadies(&rfds, n);

        }else if(n == 0){

            //60 Check for timeouts
            processTimeouts();

        }else{

            //70 check error
            int err = OSThread::GetErrno();
            switch(err)
            {
            case EINTR:
                continue;
            case EBADF:
                WARN("event_req: EBADF\n");
				continue;
            case ENOTCONN:
                ERR("event_req: ENOTCONN\n");
                continue;
            default:
                ERR("event_req: select error (%d)\n", err);
                ASSERT_C(0);
                return;
            }
        }


        //80 Fire away
        firePending();
    }

    uninit_wakeuper();

    TRACE("~~~~ Thread exit:%x ~~~~\n",(unsigned int)GetCurrentThreadID());
}