예제 #1
0
파일: http.c 프로젝트: varphone/ejs-2
static int doRequest(HttpConn *conn, cchar *url, MprList *files)
{
    MprTime         mark, remaining;
    HttpLimits      *limits;

    mprAssert(url && *url);
    limits = conn->limits;

    mprLog(MPR_DEBUG, "fetch: %s %s", app->method, url);
    mark = mprGetTime();

    if (issueRequest(conn, url, files) < 0) {
        return MPR_ERR_CANT_CONNECT;
    }
    remaining = limits->requestTimeout;
    while (!conn->error && conn->state < HTTP_STATE_COMPLETE && remaining > 0) {
        remaining = mprGetRemainingTime(mark, limits->requestTimeout);
        httpWait(conn, 0, remaining);
        readBody(conn);
    }
    if (conn->state < HTTP_STATE_COMPLETE && !conn->error) {
        httpError(conn, HTTP_ABORT | HTTP_CODE_REQUEST_TIMEOUT,
            "Inactive request timed out, exceeded request timeout %d", app->timeout);
    } else {
        readBody(conn);
    }
    reportResponse(conn, url, mprGetTime() - mark);

    httpDestroyRx(conn->rx);
    httpDestroyTx(conn->tx);
    return 0;
}
예제 #2
0
/*
    This is called when unloading a view or controller module
 */
bool espUnloadModule(cchar *module, MprTime timeout)
{
    MprModule   *mp;
    MprTime     mark;
    Esp         *esp;

    /* MOB - should this suspend new requests */
    if ((mp = mprLookupModule(module)) != 0) {
        esp = MPR->espService;
        mark = mprGetTime();
        do {
            lock(esp);
            /* Own request will count as 1 */
            if (esp->inUse <= 1) {
                mprUnloadModule(mp);
                unlock(esp);
                return 1;
            }
            unlock(esp);
            mprSleep(10);
            /* Defaults to 10 secs */
        } while (mprGetRemainingTime(mark, timeout) > 0);
    }
    return 0;
}
예제 #3
0
파일: ejsWorker.c 프로젝트: embedthis/ejs-1
static int join(Ejs *ejs, EjsVar *workers, int timeout)
{
    MprTime     mark, remaining;
    int         result, count, total;

    mark = mprGetTime(ejs);
    ejs->joining = 1;

    do {
        /*
         *  Must process all pending messages
         */
        total = 0;
        while ((count = mprServiceEvents(ejs->dispatcher, 0, MPR_SERVICE_EVENTS)) > 0) { 
            total += count;
        }
        ejs->joining = !reapJoins(ejs, workers);
        if (total == 0 && ejs->joining) {
            mprWaitForCond(ejs->dispatcher->cond, timeout);
        }
        remaining = mprGetRemainingTime(ejs, mark, timeout);
    } while (ejs->joining && remaining > 0 && !ejs->exception);

    if (ejs->exception) {
        return 0;
    }
    result = (ejs->joining) ? MPR_ERR_TIMEOUT: 0;
    ejs->joining = 0;
    return result;
}
예제 #4
0
파일: testTime.c 프로젝트: doghell/mpr-3
static void testTimeBasics(MprTestGroup *gp)
{
    MprTime     mark, now, remaining, elapsed;

    mark = mprGetTime(gp);
    assert(mark != 0);
    
    remaining = mprGetRemainingTime(gp, mark, 30000);
    assert(0 <= remaining && remaining <= 30000);

    elapsed = mprGetElapsedTime(gp, mark);
    assert(0 <= elapsed && elapsed < 30000);

    mprSleep(gp, 20);
    now = mprGetTime(gp);
    assert(mprCompareTime(mark, now) < 0);
}
예제 #5
0
파일: ejsWorker.c 프로젝트: embedthis/ejs-1
/*
 *  function waitForMessage(timeout: Number = -1): Boolean
 */
static EjsVar *workerWaitForMessage(Ejs *ejs, EjsWorker *worker, int argc, EjsVar **argv)
{
    MprTime     mark, remaining;
    int         timeout;

    timeout = (argc > 0) ? ejsGetInt(argv[0]): MAXINT;
    if (timeout < 0) {
        timeout = MAXINT;
    }
    mark = mprGetTime(ejs);
    do {
        if (mprServiceEvents(ejs->dispatcher, timeout, MPR_SERVICE_EVENTS | MPR_SERVICE_ONE_THING) > 0) {
            return (EjsVar*) ejs->trueValue;
        }
        remaining = mprGetRemainingTime(ejs, mark, timeout);
    } while (remaining > 0 && !mprIsExiting(ejs) && !ejs->exiting);
    return (EjsVar*) ejs->falseValue;
}
예제 #6
0
파일: ejsApp.c 프로젝트: embedthis/ejs-1
EjsVar *ejsServiceEvents(Ejs *ejs, int count, int timeout, int flags)
{
    MprTime     mark, remaining;
    int         rc;

    if (count < 0) {
        count = MAXINT;
    }
    if (timeout < 0) {
        timeout = MAXINT;
    }
    mark = mprGetTime(ejs);
    do {
        rc = mprServiceEvents(ejs->dispatcher, timeout, MPR_SERVICE_EVENTS | MPR_SERVICE_ONE_THING);
        if (rc > 0) {
            count -= rc;
        }
        remaining = mprGetRemainingTime(ejs, mark, timeout);
    } while (count > 0 && remaining > 0 && !mprIsExiting(ejs) && !ejs->exiting);
    return 0;
}