ready to test

This commit is contained in:
2025-07-29 16:18:23 +01:00
parent bd3d3d6da7
commit 6677c0f4e1
3 changed files with 11 additions and 5 deletions

1
.idea/misc.xml generated
View File

@@ -7,4 +7,5 @@
<option name="pythonIntegrationState" value="YES" /> <option name="pythonIntegrationState" value="YES" />
</component> </component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="WestSettings"><![CDATA[{}]]></component>
</project> </project>

2
data.c
View File

@@ -92,7 +92,7 @@ char *char_array_get_until_char(char_array_t *array, char c) {
}; };
char *char_array_get_bytes(char_array_t *array, size_t length) { char *char_array_get_bytes(char_array_t *array, size_t length) {
if (length < array->size) { if (length > array->size) {
return NULL; return NULL;
} }

View File

@@ -32,11 +32,12 @@ void *handle_connection(void *args) {
char_array_t *data = char_array_create(1024); char_array_t *data = char_array_create(1024);
price_array_t *prices = price_array_create(1024); price_array_t *prices = price_array_create(1024);
while ((bytesReceived = recv(handleArgs->client, buffer, sizeof(buffer), 0)) > 0) { while ((bytesReceived = recv(handleArgs->client, buffer, sizeof(buffer), 0)) > 0) {
printf("Client sent {%d}: |%d| \n", handleArgs->connection, bytesReceived); printf("{%d} Client sent: |%d| \n", handleArgs->connection, bytesReceived);
char_array_append(data, buffer, bytesReceived); char_array_append(data, buffer, bytesReceived);
query_or_insert_t *request; char *raw_request;
while ((request = fix_message(char_array_get_bytes(data, 9))) != NULL) { while ((raw_request = char_array_get_bytes(data, 9)) != NULL) {
//parse_request(handleArgs, request, data); //parse_request(handleArgs, request, data);
query_or_insert_t *request = fix_message(raw_request);
switch (request->insert.type) { switch (request->insert.type) {
case INSERT: case INSERT:
printf("{%d} timestamp: %d, price: %d\n", handleArgs->connection, request->insert.timestamp, request->insert.price); printf("{%d} timestamp: %d, price: %d\n", handleArgs->connection, request->insert.timestamp, request->insert.price);
@@ -48,13 +49,15 @@ void *handle_connection(void *args) {
printf("{%d} Query min: %d, max: %d avg %d\n", handleArgs->connection, request->query.mintime, request->query.maxtime, average); printf("{%d} Query min: %d, max: %d avg %d\n", handleArgs->connection, request->query.mintime, request->query.maxtime, average);
int32_t response = htonl(average); int32_t response = htonl(average);
send(handleArgs->client, (char*)&response, sizeof(response), 0); send(handleArgs->client, (char*)&response, sizeof(response), 0);
break;
default: default:
closesocket(handleArgs->client); closesocket(handleArgs->client);
free(handleArgs); free(handleArgs);
pthread_exit(NULL); pthread_exit(NULL);
exit(3); exit(3);
} }
// free(request); free(request);
free(raw_request);
} }
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
} }
@@ -64,6 +67,8 @@ void *handle_connection(void *args) {
pthread_exit(NULL); pthread_exit(NULL);
} }
query_or_insert_t *fix_message(char *message) { query_or_insert_t *fix_message(char *message) {
if (message == NULL) { if (message == NULL) {
return NULL; return NULL;