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; }
static int doRequest(HttpConn *conn, cchar *url, MprList *files) { MprFile *outFile; cchar *path; assert(url && *url); if (issueRequest(conn, url, files) < 0) { if (conn->rx && conn->rx->status) { reportResponse(conn, url); } return MPR_ERR_CANT_CONNECT; } if (app->outFilename) { path = app->loadThreads > 1 ? sfmt("%s-%s.tmp", app->outFilename, mprGetCurrentThreadName()): app->outFilename; if ((outFile = mprOpenFile(path, O_CREAT | O_WRONLY | O_TRUNC | O_TEXT, 0664)) == 0) { mprLog("error http", 0, "Cannot open %s", path); return MPR_ERR_CANT_OPEN; } } else { outFile = mprGetStdout(); } mprAddRoot(outFile); readBody(conn, outFile); while (conn->state < HTTP_STATE_COMPLETE && !httpRequestExpired(conn, -1)) { readBody(conn, outFile); httpWait(conn, 0, -1); } if (conn->state < HTTP_STATE_COMPLETE && !conn->error) { httpError(conn, HTTP_ABORT | HTTP_CODE_REQUEST_TIMEOUT, "Request timed out"); } if (app->outFilename) { mprCloseFile(outFile); } mprRemoveRoot(outFile); reportResponse(conn, url); httpDestroyRx(conn->rx); httpDestroyTx(conn->tx); return 0; }
static int doRequest(HttpConn *conn, cchar *url, MprList *files) { MprTicks mark, remaining; HttpLimits *limits; MprFile *outFile; cchar *path; assert(url && *url); limits = conn->limits; mprTrace(4, "fetch: %s %s", app->method, url); mark = mprGetTicks(); if (issueRequest(conn, url, files) < 0) { return MPR_ERR_CANT_CONNECT; } remaining = limits->requestTimeout; if (app->outFilename) { path = app->loadThreads > 1 ? sfmt("%s-%s.tmp", app->outFilename, mprGetCurrentThreadName()): app->outFilename; if ((outFile = mprOpenFile(path, O_CREAT | O_WRONLY | O_TRUNC | O_TEXT, 0664)) == 0) { mprError("Cannot open %s", path); return MPR_ERR_CANT_OPEN; } } else { outFile = mprGetStdout(); } mprAddRoot(outFile); while (!conn->tx->finalized && conn->state < HTTP_STATE_COMPLETE && remaining > 0) { remaining = mprGetRemainingTicks(mark, limits->requestTimeout); readBody(conn, outFile); httpWait(conn, 0, remaining); } 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, outFile); } if (app->outFilename) { mprCloseFile(outFile); } mprRemoveRoot(outFile); reportResponse(conn, url, mprGetTicks() - mark); httpDestroyRx(conn->rx); httpDestroyTx(conn->tx); return 0; }