1buffer_get_token_sa_pred(3)Library Functions Manualbuffer_get_token_sa_pred(3)
2
3
4
6 buffer_get_token_sa_pred - read token from buffer
7
9 #include <stralloc.h>
10 #include <buffer.h>
11
12 int buffer_get_token_sa_pred(buffer* b,stralloc* sa,
13 int (*predicate)(stralloc* * sa));
14
16 buffer_get_token_sa_pred appends data from b to sa until predicate(sa)
17 returns 1 or -1.
18
19 If predicate returns 1 once a '\n' was read, that new-line character is
20 still appended to sa -- use stralloc_chop or stralloc_chomp to get rid
21 of it. predicate can also return 0 (indicating further input is
22 required to complete the token) or -1 (abort and return -1; use this if
23 predicate wants to enfore a maximum message size or does timeout han‐
24 dling or detects a malformed message).
25
26 If reading from the buffer or allocating memory fails, buf‐
27 fer_get_token_sa_pred returns -1 and sets errno appropriately. At that
28 point sa may already contain a partial token.
29
30 On success, buffer_get_token_sa_pred returns 0.
31
33 buffer_get_token_sa_pred appends instead of overwriting so it can be
34 used on non-blocking sockets (these signal error and set errno to
35 EAGAIN; in this case you can simply call buffer_get_token_sa again when
36 select or poll indicate more data is available).
37
39 buffer_getline_sa(3), buffer_get_token(3), buffer(3)
40
41
42
43 buffer_get_token_sa_pred(3)