Exemplo n.º 1
0
//插入NAT记录
void DbServer::addNat(char* nat_id,char *dport_str){
    char sql[300];
    int id = atoi(nat_id);
    int dport = atoi(dport_str);
    sprintf(sql,"update other_nat set dport='%d',state=1 where id='%d'",dport,id);    
    if(executesql(sql))
        print_mysql_error(NULL);
    else
        printf("insert other_nat success! \n");
}
Exemplo n.º 2
0
// 返回0表示执行成功
int init_mysql()
{
	if (conn == NULL) {
		conn = mysql_init(NULL);	// init the database connection
		mysql_options(conn, MYSQL_OPT_CONNECT_TIMEOUT, &db_timeout);

		write_log("try to connect database\n");
		if (!mysql_real_connect(conn, db_host, db_user, db_passwd,
					db_name, db_port, 0, 0)) {
			write_log("connect database error:%s.\n", mysql_error(conn));
			sleep(sleep_time);
			return 1;
		} else {
			return 0;
		}
	} else {
		return executesql("set names utf8");
	}
}
Exemplo n.º 3
0
bool nulldatabase::endtransaction()
{
    return executesql("commit;", false);
}
Exemplo n.º 4
0
bool nulldatabase::begintransaction()
{
    return executesql("start transaction;", false);
}
Exemplo n.º 5
0
int work(void)
{
	static int retcnt = 0;
	int i = 0;
	static pid_t ID[100];
	static int workcnt = 0;
	int runid = 0;
	int jobs[max_running * 2 + 1];
	pid_t tmp_pid = 0;

	/* get the database info */
	//获取判题任务
	if (!get_jobs(jobs)) {
		retcnt = 0;
	}

	/* exec the submit */
	int j = 0;
	for (j = 0; jobs[j] > 0; j++) {
		runid = jobs[j];
		if (runid % oj_tot != oj_mod) {
			continue;
		}
		write_log("judging solution %d.\n", runid);
		if (workcnt >= max_running) {	// if no more client can running
			//总共有4个判题的进程,等待任何一个退出,可以在配置
			//文件中设置个数
			tmp_pid = waitpid(-1, NULL, 0);	// wait 4 one child exit
			workcnt--;
			retcnt++;
			for (i = 0; i < max_running; i++) {	// get the client id
				if (ID[i] == tmp_pid) {
					break;	// got the client id
				}
			}
			ID[i] = 0;
		} else {	// have free client
			for (i = 0; i < max_running; i++)	// find the client id
				if (ID[i] == 0) {
					break;		// got the client id
				}
		}
		if (workcnt < max_running && check_out(runid, OJ_CI)) {
			workcnt++;
			ID[i] = fork();		// start to fork
			if (ID[i] == 0) {
				write_log("judge solution %d in client%d.\n",
						runid, i);
				// 子进程运行判题客户端
				run_client(runid, i);	// if the process is the son, run it
				exit(EXIT_SUCCESS);
			}
		} else {
			ID[i] = 0;
		}
	}
	while ((tmp_pid = waitpid(-1, NULL, WNOHANG)) > 0) {
		workcnt--;
		retcnt++;
		for (i = 0; i < max_running; i++) {	// get the client id
			if (ID[i] == tmp_pid) {
				break;	// got the client id
			}
		}
		ID[i] = 0;
		write_log("client%d judge done.\n", i);
	}
	mysql_free_result(res);	// free the memory
	executesql("commit");
	write_log("total %d solution judge done.\n", retcnt);

	return retcnt;
}