コード例 #1
0
ファイル: hello.c プロジェクト: alepharchives/monkey
int main() {

	int ret;

	write_index();

	// All defaults. Bind to all interfaces, port 2001, default plugins, /tmp.
	// No callbacks are used.
	mklib_ctx ctx = mklib_init(NULL, 0, 0, "/tmp");
	if (!ctx) return 1;

	// The default has no index files, let's set index.html as one.
	ret = mklib_config(ctx, MKC_INDEXFILE, "index.html", NULL);
	if (!ret) return 1;

	// Start the server.
	mklib_start(ctx);

	// I'm now free to do my own things. I'm just going to wait for a keypress.
	printf("All set and running! Visit me, I default to localhost:2001.\n");
	printf("Press a key to exit.\n");
	getchar();

	mklib_stop(ctx);

	return 0;
}
コード例 #2
0
ファイル: lib-config.c プロジェクト: AmesianX/monkey
int main(void) {
    int workers, resume, timeout, keepalive;
    FILE *f;
    mklib_ctx ctx = mklib_init(NULL, 0, 0, NULL);

    if (!ctx)
        return 1;

    if (!mklib_config(ctx,
                MKC_WORKERS, 2,
                MKC_RESUME, MKLIB_FALSE,
                MKC_TIMEOUT, 1000,
                MKC_KEEPALIVE, MKLIB_FALSE,
                NULL))
        return 1;

    if (!mklib_get_config(ctx,
                MKC_WORKERS, &workers,
                MKC_RESUME, &resume,
                MKC_TIMEOUT, &timeout,
                MKC_KEEPALIVE, &keepalive,
                NULL))
        return 1;

    if (workers != 2 ||
            resume != MKLIB_FALSE ||
            timeout != 1000 ||
            keepalive != MKLIB_FALSE
       )
        return 1;

    if (!mklib_start(ctx))
        return 1;

    f = popen("ps -eLf | grep lib-config | grep -v run-tests | grep -v grep", "r");
    if (!f)
        return 1;
    fscanf(f, "%d\n", &workers);
    pclose(f);

    if (!mklib_stop(ctx))
        return 1;

    if (workers != 2)
        return 1;

    return 0;
}
コード例 #3
0
ファイル: quiz.c プロジェクト: AmesianX/monkey
int main() {

	// Bind to all interfaces, port 2001, default plugins, no directory.
	// Lacking the directory means that no files can be accessed, just what we want.
	// We use the data callback.
	mklib_ctx ctx = mklib_init(NULL, 0, 0, NULL);
	if (!ctx) return 1;

	mklib_callback_set(ctx, MKCB_DATA, listf);

	// Start the server.
	mklib_start(ctx);

	// I'm now free to do my own things. I'm just going to wait for a keypress.
	printf("All set and running! Visit me, I default to localhost:2001.\n");
	printf("Press a key to exit.\n");
	getchar();

	mklib_stop(ctx);

	return 0;
}