add circular buffer logic and fix makefile bug

This commit is contained in:
thorium1256
2026-05-27 19:15:44 +03:00
parent 7be1ef312e
commit 94561cfa24
7 changed files with 83 additions and 28 deletions

View File

@@ -1,6 +1,11 @@
#ifndef IRC_EVENTS_H
#define IRC_EVENTS_H
#define QUEUE_FAILURE -1
#define QUEUE_SUCCESS 0
#define QUEUE_FULL 1
#define QUEUE_EMPTY 2
typedef enum
{
IRC_EVENT_PRIVMSG,

View File

@@ -41,9 +41,13 @@ PUBLIC void IRC_Close(irc_client_t *irc);
// init
PUBLIC int IRC_Init(irc_client_t *irc);
PUBLIC void IRC_Free(irc_client_t *irc);
int IRC_InitQueue(irc_client_t *irc, int size);
PUBLIC int IRC_PollEvent(irc_event_t *event, irc_client_t *irc);
// PUBLIC int IRC_PollEvent(irc_event_t *event, irc_client_t *irc);
void IRC_PushEvent(irc_event_t *event, irc_client_t *irc);
int IRC_Enqueue(irc_event_t *data, irc_client_t *irc);
int IRC_Dequeue(irc_event_t *data, irc_client_t *irc);
int IRC_PeekQueue(irc_event_t *data, irc_client_t *irc);
#endif

View File

@@ -31,7 +31,7 @@ typedef struct {
typedef struct
{
irc_event_type_t type;
irc_message_t orig_msg;
char line[513];
} irc_event_t;
typedef struct
@@ -96,6 +96,14 @@ typedef struct
irc_connection_type_t connType;
} irc_connection_info_t;
typedef struct
{
irc_event_t *events;
int eventsSize;
int front;
int rear;
} irc_event_queue_t;
typedef struct
{
irc_connection_info_t connectionInfo;
@@ -111,13 +119,13 @@ typedef struct
/* Identity */
irc_identity_t identity;
irc_event_t* eventQueue; // lives on the heap
int eventQueuePtr;
/* Event queues */
irc_event_queue_t evtQueue;
} irc_client_t;
typedef struct {
const char *name;
void (*handler)(irc_message_t *msg, irc_client_t *irc);
} command_t;
} irc_command_t;
#endif