jobs;
24 | static pid_t ID[100]={0};
25 | static int work_cnt = 0;
26 |
27 | get_jobs(jobs);
28 | if(OJ_DEBUG){
29 | for(auto const &p: jobs){
30 | std::cout<= OJ_MAXRUNNING){
44 | pid_t tpid = waitpid(-1,NULL,0);
45 | for(i=0;i &jobs){
71 | std::map par;
72 | Json::Value sols = http_get("/judger/pending-solutions",par);
73 | //std::cout<<"get val:\n"<.
17 |
18 | #define OJ_UDP_PORT 13107
19 | #define UDP_BUFF_SIZE 2048
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | int create_udp_socket(){
28 | int ret_socket;
29 | while ((ret_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
30 | std::cerr<<"Failed to create socket, retrying."< 0) {
58 | printf("received message: \"%s\"\n", buff);
59 | }
60 | }
61 | }
62 |
63 | void clear_udp_buffer(int s){
64 | char buff[UDP_BUFF_SIZE];
65 | pollfd poll_list[1];
66 | poll_list[0].fd = s;
67 | poll_list[0].events = POLLIN|POLLPRI;
68 | while(poll(poll_list,(unsigned long)1,0) > 0){
69 | recv_udp_data(s, buff);
70 | }
71 | }
72 |
73 | void listen_udp(){
74 | int udp_socket = create_udp_socket();
75 | char buff[UDP_BUFF_SIZE];
76 |
77 | while(daemon_work());
78 |
79 | while(true){
80 | recv_udp_data(udp_socket, buff);
81 | if(!strcmp(buff, OJ_TOKEN)){
82 | clear_udp_buffer(udp_socket);
83 | while(daemon_work());
84 | }
85 | }
86 |
87 | close(udp_socket);
88 | }
--------------------------------------------------------------------------------
/src/wzoj-judger.h:
--------------------------------------------------------------------------------
1 | /*
2 | * wzoj-judger.h
3 | *
4 | * Copyright (C) 2016 - Unknown
5 | *
6 | * This program is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation; either version 2 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include