⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mserver5.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
	/* you don't need the commandline arguments anymore */	mo_free_options(set, setlen);	return 1;}intmain(int argc, char **av){	char *prog = *av;	opt *set = NULL;	int idx = 0, debug = 0, setlen = 0, listing = 0, i = 0;	str dbinit = NULL;	str err = MAL_SUCCEED;	static struct option long_options[12] = {		{"config", 1, 0, 'c'},		{"dbname", 1, 0, 0},		{"dbfarm", 1, 0, 0},		{"dbinit", 1, 0, 0},		{"daemon", 1, 0, 0},		{"debug", 2, 0, 'd'},		{"delay", 1, 0, 0},		{"help", 2, 0, 'h'},		{"help", 0, 0, '?'},		{"set", 1, 0, 's'},		{"trace", 0, 0, 't'},		{0, 0, 0, 0}	};@-We give malloc advice here. Main goal: prevent fragmentation.We do this by declaring everything below 2K as 'small'. Thesevalues will be drawn from a fixed pools of 400K.A grain size of 128 bytes is used to keep overhead low.We do this by declaring everything below 2K as 'small'. Thesevalues will be drawn from a fixed pools of 400K.A grain size of 128 bytes is used to keep overhead low.Trivial remark: for dynamically linked executables the malloptcapabilities depend on the malloc implementation used at run time.Unlike V4 we ignore the alloc_map advice, which leads to a muchfaster system start.@= mallopt	if (malloc_init) {/* for (Red Hat) Linux (6.2) unused and ignored at least as of glibc-2.1.3-15 *//* for (Red Hat) Linux (8) used at least as of glibc-2.2.93-5 */            if (mallopt(M_MXFAST, 192)) {                fprintf(stderr, "!monet: mallopt(M_MXFAST,192) fails.\n");            }#ifdef M_BLKSZ            if (mallopt(M_BLKSZ, 8*1024)) {                fprintf(stderr, "!monet: mallopt(M_BLKSZ,8*1024) fails.\n");            }#endif        }	malloc_init=0;@c#if defined(_MSC_VER) && defined(__cplusplus)	set_terminate(mserver_abort);#endif/* should be looked into        if (setlocale(LC_CTYPE, "") == NULL){                GDKfatal( "cannot set locale\n");        }*/#ifdef HAVE_MALLOPT	@:mallopt@#else	(void) malloc_init;	/* still unused */#endif	if (getcwd(monet_cwd, PATHLENGTH - 1) == NULL) {		perror("pwd");		GDKfatal("monet_init: could not determine current directory\n");	}	if (!(setlen = mo_builtin_settings(&set)))		usage(prog);	setlen = mo_add_option(&set, setlen, opt_config, "prefix", MONETDBPREFIX);	setlen = mo_add_option(&set, setlen, opt_config, "config", MONETDBCONFIG);	for (;;) {		int option_index = 0;		int c = getopt_long(argc, av, "c:d:t:r:?s:",				    long_options, &option_index);		if (c == -1)			break;		switch (c) {		case 0:			if (strcmp(long_options[option_index].name, "dbname") == 0) {				setlen = mo_add_option(&set, setlen, opt_cmdline, "gdk_dbname", optarg);				break;			}			if (strcmp(long_options[option_index].name, "delay") == 0) {				setlen = mo_add_option(&set, setlen, opt_cmdline, "delay", optarg);				break;			}			if (strcmp(long_options[option_index].name, "dbfarm") == 0) {				setlen = mo_add_option(&set, setlen, opt_cmdline, "gdk_dbfarm", optarg);				break;			}			if (strcmp(long_options[option_index].name, "dbinit") == 0) {				if (dbinit)					fprintf(stderr, "#warning: ignoring multiple --dbinit argument\n");				else					dbinit = optarg;				break;			}			if (strcmp(long_options[option_index].name, "daemon") == 0) {				setlen = mo_add_option(&set, setlen, opt_cmdline, "gdk_daemon", optarg);				break;			}			usage(prog);			break;		case 'c':			setlen = mo_add_option(&set, setlen, opt_cmdline, "config", optarg);			break;		case 'd':			debug = 1;			if (optarg) {				setlen = mo_add_option(&set, setlen, opt_cmdline, "gdk_debug", optarg);			}			break;		case 's':{			/* should add option to a list */			char *tmp = strchr(optarg, '=');			if (tmp) {				*tmp = '\0';				setlen = mo_add_option(&set, setlen, opt_cmdline, optarg, tmp + 1);			} else {				fprintf(stderr, "ERROR: wrong format %s\n", optarg);			}		}			break;		case 't':	/* trace option, ignored to reduce testweb complaints			fprintf(stderr, "#warning: trace option not yet supported\n");			*/			break;		case 'h':			if(strcmp(long_options[option_index].name, "help") == 0) {				usage2(prog);				break;			}		case '?':			usage(prog);		default:			fprintf(stderr, "ERROR: getopt returned character code 0%o ??\n", c);			usage(prog);		}	}	if (!(setlen = mo_system_config(&set, setlen)))		usage(prog);	monet_script = (str *) GDKmalloc(sizeof(str) * (argc + 1));	monet_script[idx] = NULL;	while (optind < argc) {		monet_script[idx] = absolute_path(av[optind]);		monet_script[idx + 1] = NULL;		optind++;		idx++;	}	if (debug)		mo_print_options(set, setlen);#ifdef MONET_GLOBAL_DEBUG	else		mo_print_options(set, setlen);#endif	if (monet_init(set, setlen) == 0 || mal_init())		return 0;	/* configure sabaoth to use the right dbfarm and active database */	SABAOTHinit(GDKgetenv("gdk_dbfarm"), GDKgetenv("gdk_dbname"));	/* wipe out all cruft, if left over */	if ((err = SABAOTHwildRetreat(&i)) != MAL_SUCCEED) {		/* just swallow the error */		GDKfree(err);	}	/* From this point, the server should exit cleanly.  Discussion:	 * even earlier?  Sabaoth here registers the server has started up. */	if ((err = SABAOTHregisterStart(&i)) != MAL_SUCCEED) {		/* throw the error at the user, but don't die */		fprintf(stderr, "!%s\n", err);		GDKfree(err);	}	{		str lang = "mal";		/* we inited mal before, so publish its existence */		if ((err = SABAOTHmarchScenario(&i, &lang)) != MAL_SUCCEED) {			/* throw the error at the user, but don't die */			fprintf(stderr, "!%s\n", err);			GDKfree(err);		}	}	{		/* unlock the vault, first see if we can find the file which		 * holds the secret */		char* secret = alloca(sizeof(char) * 1024);		FILE* secretf;		size_t len;				if (GDKgetenv("monet_vault_key") == NULL) {			/* use a default (hard coded, non safe) key */			secret = "Xas632jsi2whjds8";			fprintf(stderr, "#warning: please don't forget to set your "					"vault key!\n#(see %s)\n", GDKgetenv("config"));		} else {			if ((secretf = fopen(GDKgetenv("monet_vault_key"), "r")) == NULL) {				snprintf(secret, 1023, "unable to open vault_key_file %s: %s",						GDKgetenv("monet_vault_key"), strerror(errno));				secret[1023] = '\0';				GDKfatal(secret);			}			len = fread(secret, 1, 1023, secretf);			secret[len] = '\0';			len = strlen(secret); /* secret can contain null-bytes */			if (len < 5) {				fprintf(stderr, "#warning: your vault key is too short "						"(" SZFMT "), enlarge your vault key!\n",						len); /* penis */			}			fclose(secretf);		}		if ((err = AUTHunlockVault(&secret)) != MAL_SUCCEED)			GDKfatal(err);	}	/* make sure the authorisation BATs are loaded */	if ((err = AUTHinitTables()) != MAL_SUCCEED)		GDKfatal(err);@-Time to execute the script files. Start with the init command[todo], which may be defined inthe configuration file.@c	MSinitClientPrg(mal_clients, "user","main");	if (dbinit == NULL)		dbinit = GDKgetenv("dbinit");	if (dbinit) {		str input = GDKstrdup(dbinit);		callString(mal_clients, input, listing);		GDKfree(input);	}	if (GDKgetenv("mal_listing"))		sscanf(GDKgetenv("mal_listing"), "%d", &listing);	for (i = 0; monet_script[i]; i++) {		evalFile(mal_clients, monet_script[i], listing);		GDKfree(monet_script[i]);		monet_script[i] = 0;	}	GDKfree(monet_script);	if (monet_daemon) {		while(1) 			MT_sleep_ms(5000);	} else		MSserveClient(mal_clients);	/* mal_exit calls MT_global_exit, so statements after this call will	 * never get reached */	mal_exit();	return 0;}@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -