コード例 #1
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static void lstProperty(EjsMod *mp, EjsModule *module, EjsObj *block, int slotNum, EjsName qname, int attributes, 
        EjsName typeName)
{
    Ejs         *ejs;
    EjsType     *propType;
    EjsString   *space, *blockName;

    ejs = mp->ejs;
    space = mapSpace(ejs, qname.space);
    mprFprintf(mp->file, "VARIABLE:   ");

    blockName = getBlockName(mp, block, slotNum);
    mprFprintf(mp->file, "[%@-%02d]  %@ %svar %@", blockName, slotNum, space,
        getAttributeString(mp, attributes), qname.name);

    if (typeName.name && typeName.name->value[0]) {
        mprFprintf(mp->file, " : %@", typeName.name);
    }
    mprFprintf(mp->file, "\n");

    if (block == 0) {
        /*
            Nested block.
         */
        if (typeName.name) {
            propType = (EjsType*) ejsGetPropertyByName(ejs, ejs->global, typeName);
        } else {
            propType = 0;
        }
        mprAssert(mp->currentBlock && ejsIsBlock(ejs, mp->currentBlock));
        slotNum = ejsDefineProperty(ejs, (EjsObj*) mp->currentBlock, -1, qname, propType, attributes, 0);
    }
}
コード例 #2
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static void lstEndModule(EjsMod *mp, EjsModule *module)
{
    char    *pp, *end;
    ssize   size;
    int     i;

    mprAssert(mp);

    mprFprintf(mp->file,
        "\n----------------------------------------------------------------------------------------------\n");

    lstSlotAssignments(mp, module, NULL, 0, mp->ejs->global);

    /*
        Dump the constant pool
     */
    size = module->constants->poolLength;
    mprFprintf(mp->file,
        "\n----------------------------------------------------------------------------------------------\n"
        "#\n"
        "#  Constant Pool (size %d bytes)\n"
        "#\n", size);

    pp = (char*) module->constants->pool;
    end = &((char*) module->constants->pool)[size];
    for (i = 0; pp < end; i++) {
        mprFprintf(mp->file, "%04d   \"%s\"\n", i, pp);
        pp += strlen(pp) + 1;
    }
}
コード例 #3
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static void lstVarSlot(EjsMod *mp, EjsModule *module, EjsName *qname, EjsTrait *trait, int slotNum)
{
    Ejs         *ejs;
    EjsString   *space;

    mprAssert(slotNum >= 0);
    mprAssert(qname);

    ejs = mp->ejs;
    space = mapSpace(ejs, qname->space);

    if (qname->name == 0 || qname->name->value[0] == '\0') {
        mprFprintf(mp->file, "%04d    <inherited>\n", slotNum);

    } else if (trait && trait->type) {
        if (trait->type == EST(Function)) {
            mprFprintf(mp->file, "%04d    %@ function %@\n", slotNum, space, qname->name);

        } else {
            mprFprintf(mp->file, "%04d    %@ var %@: %@\n", slotNum, space, qname->name, trait->type->qname.name);
        }

    } else {
        mprFprintf(mp->file, "%04d    %@ var %@\n", slotNum, space, qname->name);
    }
}
コード例 #4
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static void lstModule(EjsMod *mp, EjsModule *module)
{
    mprFprintf(mp->file,
        "\n==============================================================================================\n\n"
        "MODULE:   %@", module->vname);

    if (module->hasInitializer) {
        mprFprintf(mp->file, " <%s>\n", module->hasInitializer ? "hasInitializer, " : "");
    }
    mprFprintf(mp->file, "\n");
}
コード例 #5
0
ファイル: httpPassword.cpp プロジェクト: OPSF/uClinux
static int updatePassFile(char *passFile)
{
	User	*up;
	char	tempFile[MPR_MAX_FNAME];
	int		fd;

	mprMakeTempFileName(tempFile, sizeof(tempFile), "httpPass", 1);
	fd = open(tempFile, O_CREAT | O_TRUNC | O_WRONLY | O_TEXT, 0664);
	if (fd < 0) {
		mprError(MPR_L, MPR_USER, "Can't open %s\n", tempFile);
		return MPR_ERR_CANT_OPEN;
	}
	up = (User*) users.getFirst();
	while (up) {
		if (mprFprintf(fd, "%d: %s: %s: %s\n", up->getEnabled(), up->getName(), 
				up->getRealm(), up->getPassword()) < 0) {
			mprError(MPR_L, MPR_USER, "Can't write to %s\n", tempFile);
			return MPR_ERR_CANT_WRITE;
		}
		up = (User*) users.getNext(up);
	}
	close(fd);
	unlink(passFile);
	if (rename(tempFile, passFile) < 0) {
		mprError(MPR_L, MPR_USER, "Can't rename %s to %s\n", tempFile, 
			passFile);
		return MPR_ERR_CANT_WRITE;
	}
	return 0;
}
コード例 #6
0
ファイル: log.cpp プロジェクト: linbc/appweb2-win
void MprLogToFile::logEvent(char *module, int flags, int level, char *thread, 
	char *msg)
{
	char		buf[MPR_MAX_LOG_STRING];

	if (mprGetMpr() == 0) {
		mprStrcpy(buf, sizeof(buf), msg);

	} else if (timeStamps) {
#if CYGWIN || LINUX || MACOSX || SOLARIS || VXWORKS || FREEBSD
#if	BLD_FEATURE_HIRES_TIME
		int64 elapsed = mprGetElapsedTime();
		mprSprintf(buf, sizeof(buf), "%,14Ld %10s:%d %s  %s", elapsed, module, 
			level, thread, msg);
#else
		static int last = 0;
		int now = mprGetTime(0);
		int elapsed = now - last;
		mprSprintf(buf, sizeof(buf), "%,14d %10s:%d %s  %s", elapsed, module, 
			level, thread, msg);
		last = now;
#endif
#endif // CYGWIN || LINUX || MACOSX || SOLARIS || VXWORKS || FREEBSD

	} else if (! (flags & MPR_RAW)) {
		mprSprintf(buf, sizeof(buf), "%10s:%d %4s  %s", module, level, thread, 
			msg);

	} else {
		//	Raw output
		mprStrcpy(buf, sizeof(buf), msg);
	}

	if (logFd < 0) {
		if (level <= 1) {
			//
			//	Always output fatal and error messages
			//
			mprFprintf(MPR_STDERR, buf);
		}
		return;
	}

	//	OPT -- could get length above
	mprAssert(logFd >= 0);
	write(logFd, buf, strlen(buf));

	if (logFd != MPR_STDOUT) {
		struct stat	sbuf;
		if (maxSize <= 0 || fstat(logFd, &sbuf) < 0) {
			return;
		}
		//
		//	Rotate logs when full
		//
		if (sbuf.st_mode & S_IFREG && (unsigned) sbuf.st_size > maxSize) {
			rotate();
		}
	}
}
コード例 #7
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static void lstBlock(EjsMod *mp, EjsModule *module, EjsObj *owner, int slotNum, EjsString *name, int numProp)
{
    EjsString   *blockName;

    blockName = getBlockName(mp, owner, slotNum);
    mprFprintf(mp->file, "BLOCK:      [%@-%02d]  %@ (Slots %d)\n", blockName, slotNum, name, numProp);
}
コード例 #8
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static uchar getByte(EjsMod *mp)
{
    if (mp->showAsm) {
        mprFprintf(mp->file, "%02x ",  mp->pc[0] & 0xFF);
    }
    return *mp->pc++ & 0xFF;
}
コード例 #9
0
ファイル: http.c プロジェクト: varphone/ejs-2
static void showOutput(HttpConn *conn, cchar *buf, ssize count)
{
    HttpRx      *rx;
    int         i, c;
    
    rx = conn->rx;

    if (app->noout) {
        return;
    }
    if (rx->status == 401 || (conn->followRedirects && (301 <= rx->status && rx->status <= 302))) {
        return;
    }
    if (app->outFile == 0) {
        if (app->outFilename) {
            if ((app->outFile = mprOpenFile(app->outFilename, O_CREAT | O_WRONLY | O_TRUNC | O_TEXT, 0664)) == 0) {
                mprError("Can't open %s", app->outFile);
                return;
            }
        } else {
            app->outFile = mprGetStdout();
        }
    }
    if (!app->printable) {
        mprWriteFile(app->outFile, buf, count);
        return;
    }
    for (i = 0; i < count; i++) {
        if (!isprint((uchar) buf[i]) && buf[i] != '\n' && buf[i] != '\r' && buf[i] != '\t') {
            app->isBinary = 1;
            break;
        }
    }
    if (!app->isBinary) {
        mprWriteFile(app->outFile, buf, count);
        return;
    }
    for (i = 0; i < count; i++) {
        c = (uchar) buf[i];
        if (app->printable && app->isBinary) {
            mprFprintf(app->outFile, "%02x ", c & 0xff);
        } else {
            mprFprintf(app->outFile, "%c", (uchar) buf[i]);
        }
    }
}
コード例 #10
0
ファイル: log.c プロジェクト: gamman/appweb-3
/*
 *  Turn on logging. If no logSpec is specified, default to stdout:2. If the user specifies --log "none" then 
 *  the log is disabled. This is useful when specifying the log via the appweb.conf.
 */
static void logHandler(MprCtx ctx, int flags, int level, cchar *msg)
{
    Mpr         *mpr;
    MprFile     *file;
    char        *prefix, buf[MPR_MAX_STRING];

    mpr = mprGetMpr(ctx);
    if ((file = (MprFile*) mpr->logHandlerData) == 0) {
        return;
    }
    prefix = mpr->name;

    while (*msg == '\n') {
        mprFprintf(file, "\n");
        msg++;
    }

    if (flags & MPR_LOG_SRC) {
        mprFprintf(file, "%s: %d: %s\n", prefix, level, msg);

    } else if (flags & MPR_ERROR_SRC) {
        mprSprintf(buf, sizeof(buf), "%s: Error: %s\n", prefix, msg);
        mprWriteToOsLog(ctx, buf, flags, level);

        /*
         *  Use static printing to avoid malloc when the messages are small.
         *  This is important for memory allocation errors.
         */
        if (strlen(msg) < (MPR_MAX_STRING - 32)) {
            mprWriteString(file, buf);
        } else {
            mprFprintf(file, "%s: Error: %s\n", prefix, msg);
        }

    } else if (flags & MPR_FATAL_SRC) {
        mprSprintf(buf, sizeof(buf), "%s: Fatal: %s\n", prefix, msg);
        mprWriteString(file, buf);
        mprWriteToOsLog(ctx, buf, flags, level);
        
    } else if (flags & MPR_RAW) {
        mprFprintf(file, "%s", msg);
    }
}
コード例 #11
0
ファイル: listing.c プロジェクト: varphone/ejs-2
/*
    List a class (type)
 */
static void lstClass(EjsMod *mp, EjsModule *module, int slotNum, EjsType *klass, int attributes)
{
    Ejs         *ejs;

    ejs = mp->ejs;
    mprFprintf(mp->file, "\n");

    if (klass->baseType) {
        mprFprintf(mp->file, "CLASS:      %sclass %@ extends %@\n", getAttributeString(mp, attributes), 
            klass->qname.name, klass->baseType->qname.name);
    } else {
        mprFprintf(mp->file, "CLASS:      %sclass %@\n", getAttributeString(mp, attributes), klass->qname.name);
    }
    leadin(mp, module, 1, 0);
    mprFprintf(mp->file, 
        "        #  Class Details: %d class traits, %d prototype (instance) traits, %s, requested slot %d\n",
        ejsGetLength(ejs, (EjsObj*) klass),
        klass->prototype ? ejsGetLength(ejs, klass->prototype) : 0, 
        klass->hasInstanceVars ? "has-state": "", slotNum);
}
コード例 #12
0
ファイル: listing.c プロジェクト: varphone/ejs-2
void lstException(EjsMod *mp, EjsModule *module, EjsFunction *fun)
{
    Ejs             *ejs;
    EjsEx           *ex;
    EjsCode         *code;
    cchar           *exKind;
    int             i;

    ejs = mp->ejs;
    code = fun->body.code;

    if (code->numHandlers <= 0) {
        return;
    }
    mprFprintf(mp->file,
        "\n"
        "#\n"
        "#  Exception Section\n"
        "#    Kind     TryStart TryEnd  HandlerStart  HandlerEnd   CatchType\n"
        "#\n");

    for (i = 0; i < code->numHandlers; i++) {
        ex = code->handlers[i];

        if (ex->flags & EJS_EX_FINALLY) {
            exKind  = "finally";
        } else if (ex->flags & EJS_EX_ITERATION) {
            exKind  = "iteration";
        } else if (ex->flags & EJS_EX_CATCH) {
            exKind = "catch";
        } else {
            exKind = "unknown";
        }
        mprFprintf(mp->file,
            "%-3d %-10s %5d   %5d      %5d        %5d       %@\n",
            i, exKind, ex->tryStart, ex->tryEnd, ex->handlerStart, ex->handlerEnd,
            ex->catchType ? ex->catchType->qname.name : ESV(empty));
    }
    mprFprintf(mp->file, "\n");
}
コード例 #13
0
ファイル: genbyte.c プロジェクト: embedthis/ejscript
static void genByteCodeHeader(Mpr *mpr, cchar *dir)
{
    MprFile     *file;
    EjsOptable  *op;
    char        *path;

    path = mprJoinPath(mpr, dir, "ejsByteCode.h");
    file = mprOpenFile(mpr, path, O_WRONLY | O_CREAT | O_TRUNC, 0664);
    if (file == 0) {
        mprError(mpr, "Cannot open %s", path);
        return;
    } 
    header(file, "ejsByteCode", "Ejscript VM Byte Code");

    mprFprintf(file, "typedef enum EjsOpCode {\n");
    for (op = ejsOptable; op->name; op++) {
        mprFprintf(file, "    EJS_OP_%s,\n", op->name);
    }
    mprFprintf(file, "} EjsOpCode;\n");
    footer(file);
    mprCloseFile(file);
}
コード例 #14
0
ファイル: log.cpp プロジェクト: linbc/appweb2-win
void MprLogToFile::stop()
{
	if (timer) {
		timer->stop(MPR_TIMEOUT_STOP);
		timer->dispose();
		timer = 0;
	}
	if (logFd >= 0 && (logFd != MPR_STDOUT)) {
		mprFprintf(logFd, "\n- End -\n");
		close(logFd);
	}
	logFd = -1;
}
コード例 #15
0
ファイル: genbyte.c プロジェクト: embedthis/ejscript
static void genByteGotoHeader(Mpr *mpr, cchar *dir)
{
    MprFile     *file;
    EjsOptable  *op;
    char        *path;

    path = mprJoinPath(mpr, dir, "ejsByteGoto.h");
    file = mprOpenFile(mpr, path, O_WRONLY | O_CREAT | O_TRUNC, 0664);
    if (file == 0) {
        mprError(mpr, "Cannot open %s", path);
        return;
    } 
    // header(file, "ejsByteGoto", "Ejscript Byte Code Jump Labels");

    mprFprintf(file, "static void *opcodeJump[] = {\n");
    for (op = ejsOptable; op->name; op++) {
        mprFprintf(file, "    &&EJS_OP_%s,\n", op->name);
    }
    mprFprintf(file, "};\n");
    // footer(file);
    mprCloseFile(file);
}
コード例 #16
0
ファイル: appweb.cpp プロジェクト: embedthis/appweb-2
static void setLogging(char *logSpec)
{
#if BLD_FEATURE_LOG
	mp->logService->setDefaultLevel(MPR_CONFIG);
	if (logSpec == 0 && !configFile && !background) {
		logSpec = "stdout:2";
	}
#if WIN
	dialog = new MprLogToWindow();
	mp->addListener(dialog);
#endif

	logger = new MprLogToFile();
	// logger->enableTimeStamps(1);
	mp->addListener(logger);

#if BLD_FEATURE_ROMFS
	//
	//	If ROMing, we can only log to stdout as we can't log to a read-only
	//	file system!! Alternatively, you can design your own listener and 
	//	install it here.
	//
	if (logSpec) {
		if (strncmp(logSpec, "stdout", 6) == 0) {
			mp->setLogSpec(logSpec);
		} else {
			mprFprintf(MPR_STDERR, "Can't log to %s when using ROMFS\n", 
				logSpec);
		}
	}
#else
	if (logSpec && mp->setLogSpec(logSpec) < 0) {
		mprFprintf(MPR_STDERR, "Can't open logSpec %s\n", logSpec);
		exit(2);
	}
#endif // BLD_FEATURE_ROMFS
#endif // BLD_FEATURE_LOG
}
コード例 #17
0
ファイル: httpPassword.cpp プロジェクト: OPSF/uClinux
static char *getPassword(char *passBuf, int passLen)
{
	char	*password, *confirm;
#if LINUX || WIN || MACOSX || SOLARIS
	password = getpass("New password: "******"Confirm password: "******"%s: Error: Password not verified\n", programName);
	return 0;
#endif
}
コード例 #18
0
ファイル: listing.c プロジェクト: varphone/ejs-2
/*
    Get an encoded number
 */
static int64 getNum(EjsMod *mp)
{
    uchar       *start;
    int64       value;

    start = mp->pc;
    value = ejsDecodeNum(mp->ejs, &mp->pc);

    if (mp->showAsm) {
        for (; start < mp->pc; start++) {
            mprFprintf(mp->file, "%02x ", *start & 0xff);
        }
    }
    return value;
}
コード例 #19
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static uint getInt32(EjsMod *mp)
{
    uchar   *start;
    uint    value;

    start = mp->pc;
    value = ejsDecodeInt32(mp->ejs, &mp->pc);

    if (mp->showAsm) {
        for (; start < mp->pc; start++) {
            mprFprintf(mp->file, "%02x ", *start & 0xff);
        }
    }
    return value;
}
コード例 #20
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static double getDouble(EjsMod *mp)
{
    uchar   *start;
    double  value;

    start = mp->pc;
    value = ejsDecodeDouble(mp->ejs, &mp->pc);

    if (mp->showAsm) {
        for (; start < mp->pc; start++) {
            mprFprintf(mp->file, "%02x ", *start & 0xff);
        }
    }
    return value;
}
コード例 #21
0
ファイル: httpPassword.cpp プロジェクト: OPSF/uClinux
static void printUsage(char *programName)
{
	mprFprintf(MPR_STDERR, 
		"usage: httpPassword [-c] [-p password] passwordFile realm user\n");
	mprFprintf(MPR_STDERR, "Options:\n");
	mprFprintf(MPR_STDERR, "    -c              Create the password file\n");
	mprFprintf(MPR_STDERR, "    -p passWord     Use the specified password\n");
	mprFprintf(MPR_STDERR, "    -e 				Enable (default)\n");
	mprFprintf(MPR_STDERR, "    -d 				Disable\n");
}
コード例 #22
0
ファイル: log.cpp プロジェクト: linbc/appweb2-win
void mprError(char *file, int line, int flags, char *fmt, ...)
{
	va_list		args;

	va_start(args, fmt);
#if BLD_FEATURE_LOG
	if (defaultLog) {
		defaultLog->error(file, line, flags, fmt, args);
	}
#else
	char	buf[MPR_MAX_LOG_STRING];
	mprVsprintf(buf, sizeof(buf), fmt, args);
	mprFprintf(MPR_STDERR, "%s\n", buf);
#endif
	va_end(args);
}
コード例 #23
0
ファイル: log.cpp プロジェクト: linbc/appweb2-win
void MprLogToFile::rotate()
{
	char bak[MPR_MAX_FNAME];

	mprSprintf(bak, sizeof(bak), "%s.old", logFileName);
	unlink(bak);

	mprFprintf(logFd, "Log size reached limit. Rotating\n");
	close(logFd);
	if (rename(logFileName, bak) != 0) {
		unlink(logFileName);
	}
	logFd = open(logFileName, O_CREAT | O_TRUNC | O_WRONLY | O_TEXT, 0664);
	rotationCount++;
	logConfig();
}
コード例 #24
0
ファイル: test.cpp プロジェクト: embedthis/appweb-2
int MprTestSession::initializeClasses(MprTestResult *result)
{
	MprTest	*tp;

	setResult(result);

	tp = (MprTest*) testList.getFirst();
	while (tp) {
		if (tp->getLevel() <= sessionLevel) {
			if (tp->classInit(result) < 0) {
				mprFprintf(MPR_STDERR, "Can't start test %s\n", tp->getName());
				return -1;
			}
		}
		tp = (MprTest*) testList.getNext(tp);
	}
	return 0;
}
コード例 #25
0
ファイル: listing.c プロジェクト: varphone/ejs-2
static int lstOpen(EjsMod *mp, char *moduleFilename, EjsModuleHdr *hdr)
{
    char    *path, *name, *ext;

    mprAssert(mp);

    name = mprGetPathBase(moduleFilename);
    if ((ext = strstr(name, EJS_MODULE_EXT)) != 0) {
        *ext = '\0';
    }
    path = sjoin(name, EJS_LISTING_EXT, NULL);
    path = mprJoinPath(mp->outputDir, path);
    if ((mp->file = mprOpenFile(path,  O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0664)) == 0) {
        mprError("Can't create %s", path);
        return EJS_ERR;
    }
    mprEnableFileBuffering(mp->file, 0, 0);
    mprFprintf(mp->file, "#\n#  %s -- Module Listing for %s\n#\n", path, moduleFilename);
    return 0;
}
コード例 #26
0
ファイル: http.c プロジェクト: gamman/appweb-3
static void logHandler(MprCtx ctx, int flags, int level, const char *msg)
{
    Mpr         *mpr;
    MprFile     *file;
    char        *prefix;

    mpr = mprGetMpr(ctx);
    file = (MprFile*) mpr->logHandlerData;
    prefix = mpr->name;

    while (*msg == '\n') {
        mprFprintf(file, "\n");
        msg++;
    }

    if (flags & MPR_LOG_SRC) {
        mprFprintf(file, "%s: %d: %s\n", prefix, level, msg);

    } else if (flags & MPR_ERROR_SRC) {
        /*
         *  Use static printing to avoid malloc when the messages are small.
         *  This is important for memory allocation errors.
         */
        if (strlen(msg) < (MPR_MAX_STRING - 32)) {
            mprStaticPrintf(file, "%s: Error: %s\n", prefix, msg);
        } else {
            mprFprintf(file, "%s: Error: %s\n", prefix, msg);
        }

    } else if (flags & MPR_FATAL_SRC) {
        mprFprintf(file, "%s: Fatal: %s\n", prefix, msg);
        
    } else if (flags & MPR_ASSERT_SRC) {
        mprFprintf(file, "%s: Assertion %s, failed\n", prefix, msg);

    } else if (flags & MPR_RAW) {
        mprFprintf(file, "%s", msg);
    }
    
    if (flags & (MPR_ERROR_SRC | MPR_FATAL_SRC | MPR_ASSERT_SRC)) {
        mprBreakpoint();
    }
}
コード例 #27
0
ファイル: winEventLoop.cpp プロジェクト: embedthis/appweb-2
int APIENTRY WinMain(HINSTANCE inst, HINSTANCE junk, char *args, 
	int junk2)
{
	MaHttp		*http;					// Http service inside our app
	MaServer	*server;				// For the HTTP server
	Mpr			mpr("winEventLoop");	// Initialize the run time

	//
	//	Do the following two statements only if you want debug trace
	//
	mp = &mpr;

#if BLD_FEATURE_LOG
	mpr.addListener(new MprLogToFile());
	mpr.setLogSpec("error.log:4");
#endif

	if (findInstance()) {
		mprError(MPR_L, MPR_LOG, "Application is already active");
		return FALSE;
	}

	//
	//	Create the window object
	// 
	if (initWindow() < 0) {
		mprError(MPR_L, MPR_ERROR, 
			"Can't initialize application Window");
		return FALSE;
	}

	//
	//	Use windows async select and message dispatcher rather than 
	//	select()
	//
	mp->setAsyncSelectMode(MPR_ASYNC_SELECT);

	//
	//	Start the Embedthis Portable Runtime and request single threading
	//	NOTE: this program can be compiled multi-threaded. If so, change
	//	the parameter to a "1".
	//
	mpr.start();

	//
	//	Create Http and Server objects for this application. We set the
	//	ServerName to be "default" and the initial serverRoot to be ".".
	//	This will be overridden in winEventLoop.conf.
	//
	http = new MaHttp();
	server = new MaServer(http, "default", ".");
	
	//
	//	Activate the copy module and handler
	//
	new MaCopyModule(0);

	//
	//	Configure the server with the configuration directive file
	//
	if (server->configure("winEventLoop.conf") < 0) {
		mprFprintf(MPR_STDERR, 
			"Can't configure the server. Error on line %d\n", 
			server->getLine());
		exit(2);
	}
	
	//
	//	Start the server
	//
	if (http->start() < 0) {
		mprFprintf(MPR_STDERR, "Can't start the server\n");
		exit(2);
	}

	//
	//	Service incoming requests until time to exit.
	//
	eventLoop();

	//
	//	Orderly shutdown
	//
	http->stop();
	mpr.stop(0);
	delete server;
	delete http;

	//
	//	MPR run-time will automatically stop and be cleaned up
	//
	return 0;
}
コード例 #28
0
ファイル: httpClient.cpp プロジェクト: embedthis/appweb-2
int main(int argc, char *argv[])
{
	double			elapsed;
	char			*programName, *argp, *logSpec;
	int				c, errflg, start;
#if BLD_FEATURE_LOG
	MprLogToFile	*logger;
#endif
#if BLD_FEATURE_MULTITHREAD
	MprThread		*threadp;
#endif

	programName = mprGetBaseName(argv[0]);
	method = "GET";
	fileList = cmpDir = writeDir = 0;
	verbose = continueOnErrors = outputHeader = errflg = 0;
	poolThreads = 4;			// Need at least one to run efficiently
	httpVersion = 1;			// HTTP/1.1
	success = 1;
	trace = 0;
	host = "localhost";
	logSpec = "stdout:1";
	postData = 0;
	postLen = 0;
	retries = MPR_HTTP_CLIENT_RETRIES;
	iterations = HTTP_DEFAULT_ITERATIONS;
	loadThreads = HTTP_DEFAULT_LOAD_THREADS;
	timeout = MPR_HTTP_CLIENT_TIMEOUT;

#if BLD_FEATURE_MULTITHREAD
	mutex = new MprMutex();
#endif

	//
	//	FUTURE: switch to GNU style --args with a better usage message
	//
	MprCmdLine	cmdLine(argc, argv, "bC:cDd:f:Hh:i:l:M:mqo:r:st:T:vV:w:");
	while ((c = cmdLine.next(&argp)) != EOF) {
		switch(c) {
		case 'b':
			benchmark++;
			break;

		case 'c':
			continueOnErrors++;
			break;

		case 'C':
			cmpDir = argp;
			break;

		case 'd':
			postData = argp;
			postLen = strlen(postData);
			break;

		case 'D':
			mprSetDebugMode(1);
			break;

		case 'f':
			fileList = argp;
			break;

		case 'h':
			host = argp;
			break;

		case 'H':
			outputHeader++;
			break;

		case 'i':
			iterations = atoi(argp);
			break;

		case 'l':
			logSpec = argp;
			break;

		case 'm':
			mprRequestMemStats(1);
			break;

		case 'M':
			method = argp;
			break;

		case 'o':
			timeout = atoi(argp);
			break;

		case 'q':
			quietMode++;
			break;

		case 'r':
			retries = atoi(argp);
			break;

		case 's':
			singleStep++;
			break;

		case 't':
			loadThreads = atoi(argp);
			break;

		case 'T':
			poolThreads = atoi(argp);
			break;

		case 'v':
			verbose++;
			trace++;
			break;

		case 'V':
			httpVersion = atoi(argp);
			break;

		case 'w':
			writeDir = argp;
			break;

		default:
			errflg++;
			break;
		}
	}
	if (writeDir && (loadThreads > 1)) {
		errflg++;
	}

	if (errflg) {
		mprFprintf(MPR_STDERR, 
			"usage: %s [-bcHMmqsTv] [-C cmpDir] [-d postData] [-f fileList]\n"
			"	[-i iterations] [-l logSpec] [-M method] [-o timeout]\n"
			"	[-h host] [-r retries] [-t threads] [-T poolThreads]\n"
			"	[-V httpVersion] [-w writeDir] [urls...]\n", programName);
		exit(2);
	}
	saveArgc = argc - cmdLine.firstArg();
	saveArgv = &argv[cmdLine.firstArg()];

	mpr = new Mpr(programName);

#if BLD_FEATURE_LOG
	tMod = new MprLogModule("httpClient");
	logger = new MprLogToFile();
	mpr->addListener(logger);
	if (mpr->setLogSpec(logSpec) < 0) {
		mprFprintf(MPR_STDERR, "Can't open log file %s\n", logSpec);
		exit(2);
	}
#endif

	//
	//	Alternatively, set the configuration manually
	//
	mpr->setAppTitle("Embedthis HTTP Client");
#if BLD_FEATURE_MULTITHREAD
	mpr->setMaxPoolThreads(poolThreads);
#endif

	//
	//	Start the Timer, Socket and Pool services
	//
	if (mpr->start(MPR_SERVICE_THREAD) < 0) {
		mprError(MPR_L, MPR_USER, "Can't start MPR for %s", mpr->getAppTitle());
		delete mpr;
		exit(2);
	}

	//
	//	Create extra test threads to run the tests as required. We use
	//	the main thread also (so start with j==1)
	//
	start = mprGetTime(0);
#if BLD_FEATURE_MULTITHREAD
	activeLoadThreads = loadThreads;
	for (int j = 1; j < loadThreads; j++) {
		char name[64];
		mprSprintf(name, sizeof(name), "t.%d", j - 1);
		threadp = new MprThread(doTests, MPR_NORMAL_PRIORITY, (void*) j, name); 
		threadp->start();
	}
#endif

	doTests(0, 0);

	//
	//	Wait for all the threads to complete (simple but effective). Keep 
	//	servicing events as we wind down.
	//
	while (activeLoadThreads > 1) {
		mprSleep(100);
	}

	if (benchmark && success) {
		elapsed = (mprGetTime(0) - start);
		if (fetchCount == 0) {
			elapsed = 0;
			fetchCount = 1;
		}
		mprPrintf("\tThreads %d, Pool Threads %d   \t%13.2f\t%12.2f\t%6d\n", 
			loadThreads, poolThreads, elapsed * 1000.0 / fetchCount, 
			elapsed / 1000.0, fetchCount);

		mprPrintf("\nTime elapsed:        %13.4f sec\n", elapsed / 1000.0);
		mprPrintf("Time per request:    %13.4f sec\n", elapsed / 1000.0 
			/ fetchCount);
		mprPrintf("Requests per second: %13.4f\n", fetchCount * 1.0 / 
			(elapsed / 1000.0));
	}
	if (! quietMode) {
		mprPrintf("\n");
	}

	mpr->stop(0);

#if BLD_FEATURE_MULTITHREAD
	delete mutex;
#endif
#if BLD_FEATURE_LOG
	delete tMod;
#endif

	delete mpr;
#if BLD_FEATURE_LOG
	delete logger;
#endif
	mprMemClose();
	return (success) ? 0 : 255;
}
コード例 #29
0
ファイル: appweb.cpp プロジェクト: embedthis/appweb-2
static void printUsage(char *programName)
{
#if WIN
	if (!isService) {
		mprError(MPR_L, MPR_USER, "Bad command line arguments");
		return;
	}
#endif
	mprFprintf(MPR_STDERR, 
		"usage: %s [-Abdkmv] [-a IP:PORT] [-d docRoot] [-f configFile]\n"
		"       [-l logSpec] [-r serverRootDir] [-t numThreads]\n\n",  
		programName);

	mprFprintf(MPR_STDERR, "Options:\n");
	mprFprintf(MPR_STDERR, "  -a IP:PORT     Address to listen on\n");
	mprFprintf(MPR_STDERR, "  -A             Disable auto-scan for a free port\n");
	mprFprintf(MPR_STDERR, "  -b             Run in background as a daemon\n");
	mprFprintf(MPR_STDERR, "  -d docRoot     Web directory (DocumentRoot)\n");

#if BLD_FEATURE_CONFIG_PARSE
	mprFprintf(MPR_STDERR, "  -f configFile  Configuration file name\n");
#else
	mprFprintf(MPR_STDERR, "  -f configFile  NOT SUPPORTED in this build\n");
#endif

	mprFprintf(MPR_STDERR, "  -k             Kill existing running http\n");
	mprFprintf(MPR_STDERR, "  -l file:level  Log to file at verbosity level\n");
	mprFprintf(MPR_STDERR, "  -r serverRoot  Alternate Home directory\n");

	mprFprintf(MPR_STDERR, "\nDebug options\n");
	mprFprintf(MPR_STDERR, "  -D             Debug mode (no timeouts)\n");
	mprFprintf(MPR_STDERR, "  -m             Output memory stats\n");
	mprFprintf(MPR_STDERR, "  -t number      Use number of pool threads\n");
	mprFprintf(MPR_STDERR, "  -v             Output version information\n");

	mprFprintf(MPR_STDERR, "\nWindows options\n");
	mprFprintf(MPR_STDERR, "  -i             Install service\n");
	mprFprintf(MPR_STDERR, "  -g             Go (start) service\n");
	mprFprintf(MPR_STDERR, "  -s             Stop service\n");
	mprFprintf(MPR_STDERR, "  -u             Uninstall service\n");
}
コード例 #30
0
ファイル: simpleEsp.cpp プロジェクト: embedthis/appweb-2
int main(int argc, char** argv)
{
	MaHttp		*http;					// Http service inside our app
	MaServer	*server;				// For the HTTP server
	Mpr			mpr("simpleEsp");		// Initialize the run time

#if BLD_FEATURE_LOG
	//
	//	Do the following two statements only if you want debug trace
	//
	mpr.addListener(new MprLogToFile());
	mpr.setLogSpec("stdout:4");
#endif

	//
	//	Start the Embedthis Portable Runtime with 10 pool threads
	//
	mpr.start(MPR_SERVICE_THREAD);

#if BLD_FEATURE_MULTITHREAD
	mpr.poolService->setMaxPoolThreads(10);
#endif

	//
	//	Create Http and Server objects for this application. We set the
	//	ServerName to be "default" and the initial serverRoot to be ".".
	//	This will be overridden in simpleEsp.conf.
	//
	http = new MaHttp();
	server = new MaServer(http, "default", ".");
	
	//
	//	Activate the ESP module and handler
	//
	new MaEspModule(0);
	new MaCopyModule(0);

	//
	//	Configure the server with the configuration directive file
	//
	if (server->configure("simpleEsp.conf") < 0) {
		mprFprintf(MPR_STDERR, 
			"Can't configure the server. Error on line %d\n", 
			server->getLine());
		exit(2);
	}

	//
	//	Define our ESP procedures
	//
	espDefineStringCFunction(0, "helloWorld", helloWorld, 0);
	
	//
	//	Start the server
	//
	if (http->start() < 0) {
		mprFprintf(MPR_STDERR, "Can't start the server\n");
		exit(2);
	}

	//
	//	Tell the MPR to loop servicing incoming requests. We can 
	//	replace this call with a variety of event servicing 
	//	mechanisms offered by AppWeb.
	//
	mpr.serviceEvents(0, -1);

	//
	//	Orderly shutdown
	//
	http->stop();
	delete server;
	delete http;

	//
	//	MPR run-time will automatically stop and be cleaned up
	//
	return 0;
}