-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidatorServer.h
58 lines (49 loc) · 2.01 KB
/
ValidatorServer.h
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
53
54
55
56
57
58
#pragma once
#include <string>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fstream>
#include <sstream>
#include "Printer.h"
#include "Comparer.h"
/// a simple validator server that handles the validate (/api/validate) and
/// generate (/api/generate) requests sent from the relay server, the typical
/// workflow is, i.e.,
/// 1. accepts connection (blocks)
/// 2. parse the command
/// 3. fork new process and call the corresponding handler
/// 4. parent process will return to accept new connection
/// the important part is that, each validation/generate request runs in
/// isolation due to alive2's internal bug.
class ValidatorServer {
public:
ValidatorServer(int port);
~ValidatorServer();
void start();
private:
int server_fd_;
int port_;
struct sockaddr_in address_;
Printer printer_;
/// handle the validate request sent from the relay server,
/// will be called in a separate forked process after the VALIDATE command
/// is properly parsed in `handle_validate_command`.
auto handle_validate_request(
const std::string &cpp_ir,
const std::string &rust_ir,
const std::string &cpp_function_name,
const std::string &rust_function_name) const -> std::string;
/// handle the generate request sent from the relay server,
/// will be called in a separate forked process after the GENERATE command
/// is properly parsed in `handle_generate_command`.
auto handle_generate_request(
const std::string &cpp_code,
const std::string &rust_code) const -> std::string;
/// handle the VALIDATE command sent from the relay server.
auto handle_validate_command(const std::string &command) const -> std::string;
/// handle the GENERATE command sent from the relay server.
auto handle_generate_command(const std::string &command) const -> std::string;
/// receive the request from the relay server and process it.
void recv_and_process_relay_server_request(int client_socket);
};