stuff
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ main
|
||||
CMakeFiles/
|
||||
.vscode/
|
||||
build/
|
||||
.DS_Store
|
||||
|
||||
20
include/server/io/dump.h
Normal file
20
include/server/io/dump.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef DUMP_H
|
||||
#define DUMP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
char loc[256];
|
||||
char* dataPtr;
|
||||
size_t dataLen;
|
||||
} dump_t;
|
||||
|
||||
bool Generic_FileExists(char* file);
|
||||
|
||||
// Pass dump_t
|
||||
void* Dump_DumpRoutine(void* dumpData);
|
||||
|
||||
#endif
|
||||
@@ -114,7 +114,10 @@ void on_data(ssize_t dataBufLen) {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("Fork failed");
|
||||
// TODO; Send TASK_REJECT packet to server to inform that task could not be processed
|
||||
// Send TASK_REJECT packet to server to inform that task could not be processed
|
||||
char errPacket[1];
|
||||
errPacket[0] = PACKET_TYPE_TASK_REJECT;
|
||||
Generic_SendSocket(sock, errPacket, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
32
src/server/io/dump.c
Normal file
32
src/server/io/dump.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <server/io/dump.h>
|
||||
#include <pthread.h>
|
||||
|
||||
bool Generic_FileExists(char* file) {
|
||||
FILE* f = fopen(file, "r");
|
||||
if (f) {
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void* Dump_DumpRoutine(void* dumpData) {
|
||||
if (!dumpData) {
|
||||
perror("Dump - dumpData ptr null!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dump_t localDump = *(dump_t*)dumpData; // Assume
|
||||
|
||||
FILE* fout = fopen(localDump.loc, "wb");
|
||||
if (!fout) {
|
||||
perror("Dump - failed to open file\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fwrite(localDump.dataPtr, localDump.dataLen, 1, fout);
|
||||
|
||||
fclose(fout);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <server/info.h>
|
||||
#include <common/packettype.h>
|
||||
#include <common/capability.h>
|
||||
#include <server/io/dump.h>
|
||||
|
||||
volatile int running = 1;
|
||||
task_queue_t taskQueue;
|
||||
@@ -221,6 +222,9 @@ void on_data(TcpClient* client) {
|
||||
memcpy(&resultDataSize, &client->dataBuf[1], sizeof(uint32_t));
|
||||
printf("Task %u result data size: %u bytes\n", task->taskId, resultDataSize);
|
||||
|
||||
dump_t dumpDefinition;
|
||||
dumpDefinition.loc = "./dump.bin";
|
||||
|
||||
// Store results
|
||||
task->assigned_to = 0;
|
||||
task->assigned_at = 0;
|
||||
|
||||
46
test_computation.c
Normal file
46
test_computation.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *file1 = fopen("input.bin", "rb");
|
||||
if (!file1) {
|
||||
perror("Error opening input.bin");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int n;
|
||||
if (fread(&n, sizeof(n), 1, file1) != 1) {
|
||||
perror("Error reading input.bin");
|
||||
fclose(file1);
|
||||
return 1;
|
||||
}
|
||||
fclose(file1);
|
||||
|
||||
printf("Got: %d\n", n);
|
||||
|
||||
// Primes or smth
|
||||
int count = 0;
|
||||
|
||||
for (int i = 2; i < 500000; i++) {
|
||||
int prime = 1;
|
||||
for (int d = 2; d * d <= n; d++) {
|
||||
if (n % d == 0) {
|
||||
prime = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
count += prime;
|
||||
n += 2;
|
||||
}
|
||||
|
||||
FILE *file2 = fopen("output.bin", "wb");
|
||||
if (!file2) {
|
||||
perror("Error opening output.bin");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fwrite(&count, sizeof(count), 1, file2);
|
||||
fclose(file2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user