-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibMessageQueue.h
40 lines (36 loc) · 940 Bytes
/
libMessageQueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "protocol.h"
#define MAX_MESSAGE_QUEUE_LEN 20
typedef struct MessageQueue {
char message[MAX_MESSAGE_QUEUE_LEN][MAX_MESSAGE_LEN];
char userName[MAX_USER_LEN];
int len; // the number of things currently in the queue
int capacity;
int active;
int fd;
} MessageQueue;
/**
* initialize a message queue
*/
void initQueue(MessageQueue *queue);
/**
* Add message to queue, if there is space and this is
* a valid message.
* params:
* MessageQueue queue: the queue we are adding to
* char *message: strlen(message)<MAX_MESSAGE_LEN
*
* return:
* 1 if queued
* 0 otherwise
*/
int enqueue(MessageQueue *queue, char *message);
/**
* dequeue the top of the queue
* params:
* MessageQueue queue: the queue we are dequeueing
* char *message: strlen(message)<MAX_MESSAGE_LEN
* return:
* 1 if dequeud
* 0 otherwise
*/
int dequeue(MessageQueue *queue, char *message);