@@ -28,12 +28,12 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
2828.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
2929.in \\n[ rst2man-indent\\n[ rst2man-indent-level ] ]u
3030..
31- .TH "RB_READ" "3" "Oct 18 , 2025" "" "librb"
31+ .TH "RB_READ" "3" "Oct 31 , 2025" "" "librb"
3232.SH NAME
3333.sp
3434\fI \% rb_read(3) \fP , \fI \% rb_recv(3) \fP , \fI \% rb_read_claim(3) \fP , \fI \% rb_read_commit(3) \fP , \fI \% rb_recv_claim(3) \fP ,
35- \fI \% rb_recv_commit(3) \fP , \fI \% rb_read_commit_claim(3) \fP , \fI \% rb_recv_commit_claim(3) \fP \- read data
36- from a ring buffer.
35+ \fI \% rb_recv_commit(3) \fP , \fI \% rb_read_commit_claim(3) \fP , \fI \% rb_recv_commit_claim(3) \fP ,
36+ \fI \% rb_readv(3) \fP , \fI \% rb_recvv(3) \fP \- read data from a ring buffer.
3737.SH SYNOPSIS
3838.INDENT 0.0
3939.INDENT 3.5
@@ -42,13 +42,16 @@ from a ring buffer.
4242#include <rb.h>
4343
4444long rb_read(struct rb *rb, void *buffer, size_t count);
45+ long rb_readv(struct rb *rb, const struct rb_iovec *vec, int iovcnt);
4546int rb_read_claim(struct rb *rb, void **buffer, size_t *count,
4647 size_t *object_size);
4748int rb_read_commit(struct rb *rb, size_t count);
4849int rb_read_commit_claim(struct rb *rb, void **buffer, size_t *count,
4950 size_t *object_size)
5051
5152long rb_recv(struct rb *rb, void *buffer, size_t count, enum rb_flags flags);
53+ long rb_recvv(struct rb *rb, const struct rb_iovec *vec, int iovcnt,
54+ enum rb_flags flags);
5255int rb_recv_claim(struct rb *rb, void **buffer, size_t *count,
5356 size_t *object_size, enum rb_flags flags);
5457int rb_recv_commit(struct rb *rb, size_t count, enum rb_flags flags);
@@ -105,6 +108,23 @@ error.
105108T}
106109.TE
107110.sp
111+ \fI \% rb_readv(3) \fP instead of accepting single buffer, takes vector of buffers instead.
112+ This is scatter \(dq input\(dq . When \fI rb \fP is not dynamic, this is equivalent of just
113+ calling \fI \% rb_read(3) \fP in a loop, one time for each buffer in \fI vec \fP vector. For
114+ dynamic buffers, created with \fB rb_dynamic \fP flag, this will behave same as
115+ if you passed single buffer with the size of all \fB vec[].len \fP , but data
116+ instead of landing in a single buffer, will be scattered across buffers in
117+ \fI vec \fP \& . This means that only single dynamic object will be taken from the
118+ buffer. Last buffer can be larger than data in the \fI rb \fP buffer, in which
119+ case all buffers will be filled in, and last buffer will have less bytes.
120+ Function returns total number of bytes read, so you should do your own math
121+ if that information matters to you. When function returns success, it is
122+ guaranteed that single call will take single object from \fI rb \fP buffer and
123+ scatter the data without interrupts \- in other words, reads are atomic.
124+ .sp
125+ \fI \% rb_recvv(3) \fP behaves the same but takes same flags as \fI \% rb_recv(3) \fP to alter per
126+ call behavior.
127+ .sp
108128\fI \% rb_read_claim(3) \fP doesn\(aq t read anything from the \fI rb \fP buffer, but instead gives
109129you all the information needed for you to perform the read. On successful
110130return, \fI buffer \fP will be pointing at first readable byte, and you can read
@@ -134,10 +154,10 @@ to the buffer, same calling \fI\%rb_read_commit(3)\fP\&. As output it defines si
134154returned \fI buffer \fP as with \fI \% rb_read_claim(3) \fP \& .
135155.SH RETURN VALUE
136156.sp
137- \fI \% rb_read(3) \fP and \fI \% rb_recv (3)\fP will return number of elements actually read from
138- ring buffer. \fI \% rb_read_commit(3) \fP , \fI \% rb_read_claim(3) \fP , \fI \% rb_recv_commit (3)\fP ,
139- \fI \% rb_recv_claim (3)\fP , \fI \% rb_read_commit_claim (3)\fP and \fI \% rb_recv_commit_claim (3)\fP return 0
140- on success.
157+ \fI \% rb_read(3) \fP , \fI \% rb_recv(3) \fP , \fI \% rb_readv(3) \fP and \fI \% rb_recvv (3)\fP will return number of
158+ elements actually read from ring buffer. \fI \% rb_read_commit(3) \fP , \fI \% rb_read_claim(3) \fP ,
159+ \fI \% rb_recv_commit (3)\fP , \fI \% rb_recv_claim (3)\fP , \fI \% rb_read_commit_claim (3)\fP and
160+ \fI \% rb_recv_commit_claim(3) \fP return 0 on success.
141161.sp
142162All functions will return \- 1 on errors with \fI errno \fP variable set that will
143163describe an error. If error is returned no data is removed from the buffer.
@@ -219,12 +239,35 @@ rb_read_commit(rb, nwritten / object_size);
219239 .EE
220240.UNINDENT
221241.UNINDENT
242+ .sp
243+ Perform scatter read on dynamic ring buffer
244+ .INDENT 0.0
245+ .INDENT 3.5
246+ .sp
247+ .EX
248+ char str[] = \(dq test\e 0data\e 0to\e 0read\e n\e 0\(dq ;
249+ char a[5], b[5], c[3], d[16];
250+ struct rb_iovec iov[] = {
251+ { .base = a, .len = sizeof(a) },
252+ { .base = b, .len = sizeof(b) },
253+ { .base = c, .len = sizeof(c) },
254+ { .base = d, .len = sizeof(d) },
255+ };
256+
257+ rb_write(rb, str, sizeof(str));
258+ rb_readv(rb, iov, rb_array_size(iov));
259+ printf(\(dq %s %s %s %s\(dq , a, b, c, d);
260+ /* will print \(dq test data to read\(dq */
261+ .EE
262+ .UNINDENT
263+ .UNINDENT
222264.SH SEE ALSO
223265.sp
224266\fI \% rb_new(3) \fP , \fI \% rb_init(3) \fP , \fI \% rb_destroy(3) \fP , \fI \% rb_cleanup(3) \fP , \fI \% rb_write(3) \fP , \fI \% rb_send(3) \fP ,
225- \fI \% rb_read(3) \fP , \fI \% rb_recv(3) \fP , \fI \% rb_read_claim(3) \fP , \fI \% rb_read_commit(3) \fP , \fI \% rb_write_claim(3) \fP ,
226- \fI \% rb_write_commit(3) \fP , \fI \% rb_clear(3) \fP , \fI \% rb_discard(3) \fP , \fI \% rb_count(3) \fP , \fI \% rb_space(3) \fP ,
227- \fI \% rb_stop(3) \fP , \fI \% rb_peek_size(3) \fP , \fI \% rb_set_hard_max_count(3) \fP
267+ \fI \% rb_writev(3) \fP , \fI \% rb_sendv(3) \fP , \fI \% rb_read(3) \fP , \fI \% rb_recv(3) \fP , \fI \% rb_readv(3) \fP , \fI \% rb_recvv(3) \fP ,
268+ \fI \% rb_read_claim(3) \fP , \fI \% rb_read_commit(3) \fP , \fI \% rb_write_claim(3) \fP , \fI \% rb_write_commit(3) \fP ,
269+ \fI \% rb_clear(3) \fP , \fI \% rb_discard(3) \fP , \fI \% rb_count(3) \fP , \fI \% rb_space(3) \fP , \fI \% rb_stop(3) \fP ,
270+ \fI \% rb_peek_size(3) \fP , \fI \% rb_set_hard_max_count(3) \fP
228271.SH AUTHOR
229272Michał Łyszczek <michal.lyszczek@bofc.pl>
230273.SH COPYRIGHT
0 commit comments