Esempio n. 1
0
bool DebugSession::waitForFinished(int msecs)
{
    QTime stopWatch;
    stopWatch.start();
    if (!waitForState(DebugSession::StoppingState, msecs)) return false;
    if (msecs != -1) msecs = msecs - stopWatch.elapsed();
    return true;
}
Esempio n. 2
0
/*  
    Wait for a request to complete. Timeout is in msec. Timeout < 0 means use default inactivity and request timeouts.
    Timeout of zero means no timeout.

    function wait(timeout: Number = -1): Boolean
 */
static EjsBoolean *http_wait(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
    MprTicks    timeout;

    timeout = (argc >= 1) ? ejsGetInt(ejs, argv[0]) : -1;
    if (timeout == 0) {
        timeout = MPR_MAX_TIMEOUT;
    }
    if (!waitForState(hp, HTTP_STATE_FINALIZED, timeout, 0)) {
        return ESV(false);
    }
    return ESV(true);
}
Esempio n. 3
0
bool LxcZone::shutdown(int timeout)
{
    State state = getState();
    if (state == State::STOPPED) {
        return true;
    }
    if (state != State::RUNNING) {
        LOGE("Could not gracefully shutdown zone " << getName());
        return false;
    }

#ifdef USE_EXEC
    utils::CArgsBuilder args;
    std::string timeoutStr = std::to_string(timeout);
    args.add("lxc-stop")
    .add("-n").add(mLxcContainer->name)
    .add("-P").add(mLxcContainer->config_path)
    .add("-t").add(timeoutStr.c_str())
    .add("--nokill");

    if (!utils::executeAndWait("/usr/bin/lxc-stop", args.c_array())) {
        LOGE("Could not gracefully shutdown zone " << getName() << " in " << timeout << "s");
        return false;
    }

    refresh();
    return true;
#else
    // try shutdown by sending poweroff to init
    if (setRunLevel(utils::RUNLEVEL_POWEROFF)) {
        if (!waitForState(State::STOPPED, timeout)) {
            LOGE("Could not gracefully shutdown zone " << getName() << " in " << timeout << "s");
            return false;
        }
        return true;
    }
    LOGW("SetRunLevel failed for zone " + getName());

    // fallback for other inits like bash: lxc sends 'lxc.haltsignal' signal to init
    if (!mLxcContainer->shutdown(mLxcContainer, timeout)) {
        LOGE("Could not gracefully shutdown zone " << getName() << " in " << timeout << "s");
        return false;
    }
    return true;
#endif
}
Esempio n. 4
0
/*  
    function readString(count: Number = -1): String
    Read count bytes (default all) of content as a string. This always starts at the first character of content.
 */
static EjsString *http_readString(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv)
{
    EjsString   *result;
    ssize       count;
    
    count = (argc == 1) ? ejsGetInt(ejs, argv[0]) : -1;
    if (!waitForState(hp, HTTP_STATE_CONTENT, -1, 1)) {
        return 0;
    }
    if ((count = readHttpData(ejs, hp, count)) < 0) {
        assert(ejs->exception);
        return 0;
    } else if (count == 0 && hp->conn->state > HTTP_STATE_CONTENT) {
        return ESV(null);
    }
    //  UNICODE ENCODING
    result = ejsCreateStringFromMulti(ejs, mprGetBufStart(hp->responseContent), count);
    mprAdjustBufStart(hp->responseContent, count);
    mprResetBufIfEmpty(hp->responseContent);
    return result;
}
Esempio n. 5
0
		void
		Thread::waitForReadyState () const
		{
			waitForState (Thread::READY);
		}