summaryrefslogtreecommitdiff
path: root/draft/mcastseed/src/dgrambuf.h
blob: a83647badd99236f764d889d54597e0bc116dcad (plain)
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
#ifndef DGRAMBUF_H
#define DGRAMBUF_H
/*
 * dgrambuf.c - C datagrams buffer.
 *
 * Copyright 2016 by Ludovic Pouzenc <ludovic@pouzenc.fr>
 */
#include <stdlib.h> /* size_t */

#define DGRAMBUF_RECV_OVERWRITE 1 << 1
#define DGRAMBUF_RECV_EINTR 1 << 2
#define DGRAMBUF_RECV_IOVEC_FULL 1 << 3
#define DGRAMBUF_RECV_FINALIZE 1 << 4
#define DGRAMBUF_RECV_FUTURE_DGRAM 1 << 5
#define DGRAMBUF_RECV_DUPLICATE_DGRAM 1 << 6
#define DGRAMBUF_RECV_VALID_DGRAM 1 << 6

#define DGRAMBUF_WRITE_PARTIAL 1 << 1
#define DGRAMBUF_WRITE_EWOULDBLOCK_OR_EINTR 1 << 2
#define DGRAMBUF_WRITE_IOVEC_FULL 1 << 3
#define DGRAMBUF_WRITE_SUCCESS 1 << 4

typedef struct dgrambuf_t *dgrambuf_t;

dgrambuf_t dgrambuf_new(size_t dgram_slots, size_t dgram_max_size, size_t dgram_header_size, size_t iovec_slots);
void dgrambuf_free(dgrambuf_t *);

void dgrambuf_set_validate_func(dgrambuf_t dbuf, int (*validate_func)(unsigned int, void *, unsigned int *));

size_t dgrambuf_get_free_count(const dgrambuf_t);
size_t dgrambuf_get_used_count(const dgrambuf_t);
int dgrambuf_have_data_ready_to_write(const dgrambuf_t);
int dgrambuf_have_received_everything(const dgrambuf_t);

int dgrambuf_stats(dgrambuf_t dbuf, char **allocated_string);

/* Warning : dgrambuf_recvmmsg sets and restore SIGALRM handler if timeout != 0 */
ssize_t dgrambuf_recvmmsg(dgrambuf_t dbuf, int sockfd, int timeout, int *info);
ssize_t dgrambuf_write(dgrambuf_t dbuf, int fd, int *info);

#endif /* DGRAMBUF_H */