-
Notifications
You must be signed in to change notification settings - Fork 2
/
shmq.h
executable file
·74 lines (59 loc) · 1.64 KB
/
shmq.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
#ifndef ASYNC_SERVER__SHMQ_H_
#define ASYNC_SERVER__SHMQ_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <unistd.h>
#include <libtaomee/atomic.h>
#include "net.h"
#define LOCKED_MASK 0x01
#define SLEEP_MASK 0x02
#define SHM_BLOCK_LEN_MAX 1<<23
enum {
DATA_BLOCK = 0,
PAD_BLOCK,
FIN_BLOCK, // child informs parent to close a connection
OPEN_BLOCK,
CLOSE_BLOCK // parent informs child that a connection had been closed
};
typedef struct shm_head {
volatile int head;
volatile int tail;
atomic_t blk_cnt;
} __attribute__ ((packed)) shm_head_t;
typedef struct shm_queue {
shm_head_t* addr;
u_int length;
int pipe_handles[2];
} shm_queue_t;
typedef struct shm_block {
uint32_t id;
uint32_t fd;
uint32_t length; // length of the whole shmblock, including data
char type;
uint8_t data[];
} __attribute__ ((packed)) shm_block_t;
struct bind_config_elem;
struct bind_config;
int shmq_create(struct bind_config_elem* bc_elem);
void do_destroy_shmq(struct bind_config_elem* bc_elem);
void shmq_destroy(const struct bind_config_elem* exclu_bc_elem, int max_shmq_num);
int shmq_push(shm_queue_t* q, shm_block_t* mb, const void* data);
int shmq_pop(struct shm_queue *q, struct shm_block **mb);
char* shmblk_dump(const struct shm_block *mb);
static inline void
epi2shm(int fd, struct shm_block *mb)
{
mb->id = epi.fds[fd].id;
mb->fd = fd;
mb->type = DATA_BLOCK;
mb->length = epi.fds[fd].cb.rcvprotlen + sizeof (struct shm_block);
}
extern void close_shmq_pipe(struct bind_config* bc, int idx, int is_child);
#ifdef __cplusplus
}
#endif
#endif // ASYNC_SERVER__SHMQ_H_