You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4 KiB

.TH buffer_get_token_sa_pred 3
buffer_get_token_sa_pred \- read token from buffer
.B #include <stralloc.h>
.B #include <buffer.h>
int \fBbuffer_get_token_sa_pred\fP(buffer* \fIb\fR,stralloc* \fIsa\fR,
int (*\fIpredicate\fR)(stralloc* * \fIsa\fR));
buffer_get_token_sa_pred appends data from the \fIb\fR to \fIsa\fR until
\fIpredicate\fR(\fIsa\fR) returns 1 or -1.
If \fIpredicate\fR returns 1 once a '\\n' was read, that new-line
character is still appended to \fIsa\fR -- use stralloc_chop or
stralloc_chomp to get rid of it. \fIpredicate\fR can also return 0
(indicating further input is required to complete the token) or -1
(abort and return -1; use this if \fIpredicate\fR wants to enfore a
maximum message size or does timeout handling or detects a malformed
If reading from the buffer or allocating memory fails,
buffer_get_token_sa_pred returns -1 and sets \fIerrno\fR appropriately. At
that point \fIsa\fR may already contain a partial token.
On success, buffer_get_token_sa_pred returns 0.
buffer_get_token_sa_pred appends instead of overwriting so it can be
used on non-blocking sockets (these signal error and set \fIerrno\fR to
EAGAIN; in this case you can simply call buffer_get_token_sa again when
\fBselect\fR or \fBpoll\fR indicate more data is available).
buffer_getline_sa(3), buffer_get_token(3), buffer(3)