summaryrefslogtreecommitdiff
path: root/mcastseed/src/dgrambuf.h
blob: 4d712c65d6c4690157694f39ef50210dd0f8f602 (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
#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_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 */