Skip to content

Commit

Permalink
#37
Browse files Browse the repository at this point in the history
  • Loading branch information
joegasewicz committed Jun 18, 2024
1 parent fab5c43 commit 25583a8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
} \
}\

#define FMQ_ARRAY_LENGTH(arr) sizeof(arr) / sizeof(arr[0])

#endif //CONFIG_H
23 changes: 21 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,32 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include "config.h"
#include "tcp.h"
#include "queue.h"


int main(void)
int main(int argc, char *argv[])
{
FMQ_Queue *queue = FMQ_Queue_new();
int16_t msg_size = 1024;
for (int i = 0; i < argc; i++)
{
if (strcmp(argv[i], "--msg-size") == 0)
{
if (argc < i+1)
{
printf("--msg-size arg expects an integer value\n");
exit(EXIT_FAILURE);
}
char *msg_size_char = argv[i+1];
msg_size = atoi(msg_size_char);
FMQ_LOGGER("Set queue message size to %s\n", msg_size_char);
}
}
FMQ_Queue *queue = FMQ_Queue_new(msg_size);
FMQ_TCP *tcp = FMQ_TCP_new(queue);
const int err = tcp->start(tcp);
if (tcp != NULL)
Expand Down
4 changes: 2 additions & 2 deletions provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
#ifndef PROVIDER_H
#define PROVIDER_H
#include <stdbool.h>
#include <stdint.h>

typedef struct FMQ_Provider FMQ_Provider;

struct FMQ_Provider
{

void* data; // extra data from client
bool destroy;
int16_t msg_size;
};

#endif //PROVIDER_H
3 changes: 2 additions & 1 deletion queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FMQ_QNode *FMQ_QNode_new(void *data)
return n; // TODO free
}

FMQ_Queue *FMQ_Queue_new(void)
FMQ_Queue *FMQ_Queue_new(int16_t msg_size)
{
FMQ_Queue *q = (FMQ_Queue*)malloc(sizeof(FMQ_Queue));
if (q == NULL)
Expand All @@ -52,6 +52,7 @@ FMQ_Queue *FMQ_Queue_new(void)
q->head = NULL;
q->tail = NULL;
q->size = 0;
q->msg_size = msg_size;
return q; // TODO free
}

Expand Down
4 changes: 3 additions & 1 deletion queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
#ifndef QUEUE_H
#define QUEUE_H
#include <stdint.h>

typedef struct FMQ_QNode FMQ_QNode;
typedef struct FMQ_Queue FMQ_Queue;
Expand All @@ -41,6 +42,7 @@ struct FMQ_Queue
char *status;
FMQ_QNode *head;
FMQ_QNode *tail;
int16_t msg_size;
};

struct FMQ_Data
Expand All @@ -51,7 +53,7 @@ struct FMQ_Data
#define FMQ_QUEUE_PEAK(queue) (queue->head)
#define FMQ_QUEUE_SIZE(queue) (queue->size)
FMQ_QNode *FMQ_QNode_new(void *data);
FMQ_Queue *FMQ_Queue_new(void);
FMQ_Queue *FMQ_Queue_new(int16_t msg_size);
void FMQ_Queue_enqueue(FMQ_Queue *queue, void *data);
FMQ_QNode *FMQ_Queue_dequeue(FMQ_Queue *queue);
void FMQ_QUEUE_detroy(FMQ_Queue *queue);
Expand Down
3 changes: 2 additions & 1 deletion tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ static int callback_provider(const struct _u_request *request,
}
FMQ_LOGGER("Received: %s\n", message);
FMQ_Data *data = (FMQ_Data*)malloc(sizeof(FMQ_Queue));
data->message = malloc(sizeof(char) * 1024);
const FMQ_Queue *q = (FMQ_Queue*)queue;
data->message = malloc(sizeof(char) * q->msg_size);
strcpy(data->message, message);
FMQ_Queue_enqueue((FMQ_Queue*)queue, data);

Expand Down

0 comments on commit 25583a8

Please sign in to comment.