-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
52 lines (49 loc) · 1.42 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include"Language.h"
#include"Judge.h"
#include"toolkit.h"
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
queue<int>pipelist;
queue<string>result;
LanguageManager lang_pool;
char task_buffer[4096];
int main() {
enterDir("workdir_example");
//////////////////////////////////////////
if (isWorkDir() == 0)return 0;////////////
///////////////read configuration/////////
int asdf= access("./support_lang", 0);
cout << asdf;
FILE *pLang = fopen("./support_lang", "r");
string lang_config; int len = 0;
while (fgets(task_buffer, 4095, pLang))
lang_config += task_buffer;
fclose(pLang);
lang_pool = parseLanguage(lang_config);
///////////////apocalypse/////////////////
if (access("judger_in.fifo", 0) == ENOENT)
mkfifo("judger_in.fifo", 777);
FILE *ear; int pipe_line[2];
while (1) {
ear = fopen("judger_in.fifo", "r");
while (fgets(task_buffer, 4096, ear)) {//hang up
pipe(pipe_line);
int proc = fork();
if (proc == 0) {
Task new_task = parseTask(task_buffer); Judge high;
high.judge(new_task); memset(task_buffer, 0, sizeof task_buffer);
sprintf(task_buffer, "%d %d %d %s", high.status, high.score, high.memory_usage, high.time_usage, high.compiler_info);
write(pipe_line[1], task_buffer, 2048);
return 0;
}
pipelist.push(pipe_line[0]);
while (read(pipelist.front(), task_buffer, 2048)) {
result.push(task_buffer);
pipelist.pop();
}
}
fclose(ear);
}
}