-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
43 lines (36 loc) · 951 Bytes
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "defs.h"
#include "decode/decode.h"
#include "state.h"
#include "stateutils.h"
#include "controlsocket.h"
#include "controlcommands.h"
#include "runner.h"
int main(void) {
struct EmuState state;
struct socketinfo info;
int client;
packet_type type;
void* payload;
build_decode_functions();
init_state(&state);
init_socket(&info, "/tmp/yasp");
printf("waiting for a connection\n");
if(!accept_client(&info, &client)) {
return EXIT_FAILURE;
}
printf("waiting for commands\n");
while (true) {
if(!read_command(client, &type, &payload)) {
printf("invalid command %d", type);
return EXIT_FAILURE;
}
if(!handle_packet(&state, client, type, payload)) {
printf("cannot handle command");
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}