send tasks
This commit is contained in:
12
include/common/capability.h
Normal file
12
include/common/capability.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef CAPABILITY_H
|
||||
#define CAPABILITY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
char name[32];
|
||||
bool supported;
|
||||
} capability_t;
|
||||
|
||||
#endif
|
||||
@@ -54,4 +54,4 @@ void DynArr_destroy(DynArr* p);
|
||||
|
||||
#define DYNARR_CREATE(T, initialCapacity) DynArr_create(sizeof(T), initialCapacity)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
20
include/common/dynset.h
Normal file
20
include/common/dynset.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef DYNSET_H
|
||||
#define DYNSET_H
|
||||
|
||||
#include <common/dynarr.h>
|
||||
|
||||
// Dynamic Set structure - basically DynArr with uniqueness enforced
|
||||
typedef struct {
|
||||
DynArr* arr;
|
||||
} DynSet;
|
||||
|
||||
// Function prototypes
|
||||
DynSet* DynSet_Create(size_t elemSize);
|
||||
void DynSet_Destroy(DynSet* set);
|
||||
int DynSet_Insert(DynSet* set, const void* element);
|
||||
int DynSet_Contains(DynSet* set, const void* element);
|
||||
size_t DynSet_Size(DynSet* set);
|
||||
void* DynSet_Get(DynSet* set, size_t index);
|
||||
void DynSet_Remove(DynSet* set, const void* element);
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <string.h>
|
||||
|
||||
unsigned char random_byte(void);
|
||||
uint16_t random_two_byte(void);
|
||||
uint32_t random_four_byte(void);
|
||||
uint64_t random_eight_byte(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
15
include/common/packettype.h
Normal file
15
include/common/packettype.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef PACKETTYPE_H
|
||||
#define PACKETTYPE_H
|
||||
|
||||
typedef enum {
|
||||
PACKET_TYPE_NONE = 0,
|
||||
PACKET_TYPE_HELLO = 1,
|
||||
PACKET_TYPE_TASK_ASSIGN = 2,
|
||||
PACKET_TYPE_TASK_RESULT = 3,
|
||||
PACKET_TYPE_STATUS_UPDATE = 4,
|
||||
PACKET_TYPE_CLIENT_CAPABILITIES = 5,
|
||||
PACKET_TYPE_TASK_REQUEST = 6,
|
||||
PACKET_TYPE_MISSING_INFO = 7
|
||||
} PacketType;
|
||||
|
||||
#endif
|
||||
@@ -38,9 +38,10 @@ typedef struct {
|
||||
task_state_t state;
|
||||
uint32_t assigned_to;
|
||||
time_t assigned_at;
|
||||
DynArr* results;
|
||||
} task_t;
|
||||
|
||||
void Task_Create(task_t* tsk);
|
||||
void Task_DestroyArgs(task_t* task);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <common/dynarr.h>
|
||||
|
||||
#define MTU 1500
|
||||
|
||||
@@ -15,13 +16,16 @@ struct TcpClient {
|
||||
struct sockaddr_in clientAddr;
|
||||
uint32_t clientId;
|
||||
|
||||
unsigned char dataBuf[MTU];
|
||||
unsigned char dataBuf[MTU];
|
||||
ssize_t dataBufLen;
|
||||
void (*on_data)(struct TcpClient* client);
|
||||
void (*on_disconnect)(struct TcpClient* client);
|
||||
|
||||
DynArr* capabilities;
|
||||
|
||||
pthread_t clientThread;
|
||||
};
|
||||
|
||||
typedef struct TcpClient TcpClient;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
#include <common/tcpd/tcpclient.h>
|
||||
#include <common/numgen.h>
|
||||
#include <common/dynarr.h>
|
||||
#include <common/capability.h>
|
||||
|
||||
typedef struct {
|
||||
int sockFd;
|
||||
@@ -51,4 +53,4 @@ void TcpServer_KillClient(TcpServer* ptr, TcpClient* cli);
|
||||
|
||||
size_t Generic_FindClientInArrayByPtr(TcpClient** arr, TcpClient* ptr, size_t len);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
10
include/server/info.h
Normal file
10
include/server/info.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef INFO_H
|
||||
#define INFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SERVER_HELLO_PACKET_SIZE 17 // 1 byte version + 16 byte identifier
|
||||
const uint8_t SERVER_INFO_VERSION = 1;
|
||||
const char SERVER_INFO_IDENTIFIER[16] = "EXAMPLE_SERVER\0";
|
||||
|
||||
#endif
|
||||
@@ -14,4 +14,4 @@ void TaskQueue_AddTask(task_queue_t* queue, task_t* task);
|
||||
void TaskQueue_RemoveTask(task_queue_t* queue, size_t idx);
|
||||
void TaskQueue_RemoveTaskByPtr(task_queue_t* queue, task_t* task);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user