-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbenchmark_engine.cpp
69 lines (51 loc) · 1.45 KB
/
benchmark_engine.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Define the buffer size
#define BUFFER_SIZE 1024
// Define the chunk size
#define CHUNK_SIZE 256
// Define the buffer
char buffer[BUFFER_SIZE];
// Define the chunk
char chunk[CHUNK_SIZE];
// Define the JSON object
json_t* json;
// Define the error variable
int error;
// Create a socket to listen for incoming connections
int sock = socket(AF_INET, SOCK_STREAM, 0);
// Define the server address
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8080);
inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);
// Bind the socket to the server address
bind(sock, (struct sockaddr*)&server_addr, sizeof(server_addr));
// Listen for incoming connections
listen(sock, 1);
// Accept an incoming connection
int client_sock = accept(sock, NULL, NULL);
// Receive the JSON string from the client in chunks
while (1) {
// Receive a chunk of data from the client
int bytes_received = recv(client_sock, chunk, CHUNK_SIZE, 0);
// Check if the chunk is empty
if (bytes_received == 0) {
break;
}
// Append the chunk to the buffer
strcat(buffer, chunk);
// Validate the chunk
json = json_loads(buffer, 0, &error);
// Check for errors
if (error != 0) {
// Handle the error
printf("Error parsing JSON: %s\n", json_error_string(error));
return 1;
}
// Write the chunk to the knowledge graph
// ...
}
// Close the socket
close(client_sock);
close(sock);
// Free the JSON object
json_decref(json);