-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmqueue.h
103 lines (90 loc) · 3.52 KB
/
mqueue.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*****************************************************************************
*
* POSIX Message Queue library implemented using memory mapped files
*
*****************************************************************************/
#ifndef __mqueue_h
#define __mqueue_h
#include <pthread.h>
#if defined(WIN32)
# include <WinSock2.h>
# include <windows.h>
# include <fcntl.h>
# ifndef EMSGSIZE
# define EMSGSIZE 4200
# endif
# define O_NONBLOCK 0200000
union sigval {
int sival_int; /* integer value */
void *sival_ptr; /* pointer value */
};
struct sigevent {
int sigev_notify; /* notification type */
int sigev_signo; /* signal number */
union sigval sigev_value; /* signal value */
};
typedef int pid_t;
typedef int ssize_t;
#endif
/*****************************************************************************/
typedef struct mq_info *mqd_t; /* opaque datatype */
struct mq_attr {
long mq_flags; /* message queue flag: O_NONBLOCK */
long mq_maxmsg; /* max number of messages allowed on queue */
long mq_msgsize; /* max size of a message (in bytes) */
long mq_curmsgs; /* number of messages currently on queue */
};
/* one mq_hdr{} per queue, at beginning of mapped file */
struct mq_hdr {
struct mq_attr mqh_attr; /* the queue's attributes */
long mqh_head; /* index of first message */
long mqh_free; /* index of first free message */
long mqh_nwait; /* #threads blocked in mq_receive() */
pid_t mqh_pid; /* nonzero PID if mqh_event set */
struct sigevent mqh_event; /* for mq_notify() */
#if defined(WIN32)
HANDLE mqh_lock; /* mutex lock */
HANDLE mqh_wait; /* and condition event */
#else
pthread_mutex_t mqh_lock; /* mutex lock */
pthread_cond_t mqh_wait; /* and condition variable */
#endif
};
/* one msg_hdr{} at the front of each message in the mapped file */
struct msg_hdr {
long msg_next; /* index of next on linked list */
/* msg_next must be first member in struct */
ssize_t msg_len; /* actual length */
unsigned int msg_prio; /* priority */
};
/* one mq_info{} malloc'ed per process per mq_open() */
struct mq_info {
#if defined(WIN32)
HANDLE mqi_fmap; /* file mapping object */
#endif
struct mq_hdr *mqi_hdr; /* start of mmap'ed region */
long mqi_magic; /* magic number if open */
int mqi_flags; /* flags for this process */
};
#define MQI_MAGIC 0x98765432
/* size of message in file is rounded up for alignment */
#define MSGSIZE(i) ((((i) + sizeof(long)-1) / sizeof(long)) * sizeof(long))
#ifdef __cplusplus
extern "C" {
#endif
/* message queue functions */
extern int mq_close(mqd_t);
extern int mq_getattr(mqd_t, struct mq_attr *);
extern int mq_notify(mqd_t, const struct sigevent *);
extern mqd_t mq_open(const char *, int, ...);
extern ssize_t mq_receive(mqd_t, char *, size_t, unsigned int *);
extern int mq_send(mqd_t, const char *, size_t, unsigned int);
extern int mq_setattr(mqd_t, const struct mq_attr *, struct mq_attr *);
extern int mq_unlink(const char *name);
ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr,
size_t msg_len, unsigned int *msg_prio,
const struct timespec *abs_timeout);
#ifdef __cplusplus
}
#endif
#endif