summaryrefslogtreecommitdiff
path: root/lib/libevent/evbuffer_new.3
blob: 364f67bb00bae474d0e77e386444fbeabddbb045 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
.\"	$OpenBSD: evbuffer_new.3,v 1.14 2018/07/26 12:50:04 rob Exp $
.\"
.\" Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: July 26 2018 $
.Dt EVBUFFER_NEW 3
.Os
.Sh NAME
.Nm evbuffer_new ,
.Nm evbuffer_free ,
.Nm evbuffer_setcb ,
.Nm evbuffer_expand ,
.Nm evbuffer_add ,
.Nm evbuffer_add_buffer ,
.Nm evbuffer_add_printf ,
.Nm evbuffer_add_vprintf ,
.Nm evbuffer_drain ,
.Nm evbuffer_remove ,
.Nm evbuffer_write ,
.Nm evbuffer_read ,
.Nm evbuffer_find ,
.Nm evbuffer_readline ,
.Nm evbuffer_readln ,
.Nm EVBUFFER_LENGTH ,
.Nm EVBUFFER_DATA
.Nd libevent utility API for buffered input/output
.Sh SYNOPSIS
.In event.h
.Ft "struct evbuffer *"
.Fn "evbuffer_new" "void"
.Ft void
.Fn "evbuffer_free" "struct evbuffer *buf"
.Ft void
.Fo evbuffer_setcb
.Fa "struct evbuffer *buf"
.Fa "void (*cb)(struct evbuffer *, size_t, size_t, void *)"
.Fa "void *cbarg"
.Fc
.Ft int
.Fn "evbuffer_expand" "struct evbuffer *buf" "size_t datlen"
.Ft int
.Fn "evbuffer_add" "struct evbuffer *buf" "const void *data" "size_t size"
.Ft int
.Fn "evbuffer_add_buffer" "struct evbuffer *dst" "struct evbuffer *src"
.Ft int
.Fn "evbuffer_add_printf" "struct evbuffer *buf" "const char *fmt" "..."
.Ft int
.Fn "evbuffer_add_vprintf" "struct evbuffer *buf" "const char *fmt" "va_list ap"
.Ft void
.Fn "evbuffer_drain" "struct evbuffer *buf" "size_t size"
.Ft int
.Fn "evbuffer_remove" "struct evbuffer *buf" "void *data" "size_t datlen"
.Ft int
.Fn "evbuffer_write" "struct evbuffer *buf" "int fd"
.Ft int
.Fn "evbuffer_read" "struct evbuffer *buf" "int fd" "int size"
.Ft "u_char *"
.Fn "evbuffer_find" "struct evbuffer *buf" "const u_char *data" "size_t size"
.Ft "char *"
.Fn "evbuffer_readline" "struct evbuffer *buf"
.Ft "char *"
.Fo evbuffer_readln
.Fa "struct evbuffer *buf"
.Fa "size_t *read_out"
.Fa "enum evbuffer_eol_style eol_style"
.Fc
.Ft size_t
.Fn "EVBUFFER_LENGTH" "const struct evbuffer *buf"
.Ft "u_char *"
.Fn "EVBUFFER_DATA" "const struct evbuffer *buf"
.Sh DESCRIPTION
The evbuffer API provides an implementation of buffering for use with
libevent.
.Pp
.Fn evbuffer_new
allocates and initialises a new evbuffer structure.
.Pp
.Fn evbuffer_free
deallocates the evbuffer structure
.Fa buf
and any referenced storage.
.Pp
.Fn evbuffer_setcb
sets the callback
.Fa cb
to be invoked with argument
.Fa cbarg
when the data in evbuffer
.Fa buf
is modified.
.Pp
.Fn evbuffer_expand
expands the available space in
.Fa buf
to at least
.Fa datlen
bytes.
.Pp
.Fn evbuffer_add
appends a copy of
.Fa size
bytes from buffer
.Fa data
to the end of the evbuffer
.Fa buf .
.Pp
.Fn evbuffer_add_buffer
moves the data off the
.Fa src
evbuffer and appends it to
.Fa dst .
.Pp
.Fn evbuffer_add_printf
appends a
.Xr printf 3
style formatted string specified by
.Fa fmt
to the end of
.Fa buf .
.Pp
.Fn evbuffer_add_vprintf
appends a
.Xr vprintf 3
style formatted string specified by
.Fa fmt
with a va_list
.Fa ap
to the end of
.Fa buf .
.Pp
.Fn evbuffer_drain
deletes
.Fa size
bytes from the beginning of the evbuffer
.Fa buf .
.Pp
.Fn evbuffer_remove
reads and drains up to
.Fa datlen
bytes from the beginning of the evbuffer
.Fa buf
into
.Fa data .
.Pp
.Fn evbuffer_write
writes and drains the contents of evbuffer
.Fa buf
to the file descriptor
.Fa fd .
.Pp
.Fn evbuffer_read
appends up to
.Fa size
bytes on to the end of the evbuffer
.Fa buf
by reading from the file descriptor
.Fa fd .
.Pp
.Fn evbuffer_find
finds the
.Fa size
length string
.Fa data
in the evbuffer
.Fa buf .
.Pp
.Fn evbuffer_readline
reads and drains a single line from the evbuffer
.Fa buf .
A line is delimited by "\en", "\er", "\er\en", or "\en\er".
It is the responsibility of the caller to free the returned line with
.Xr free 3 .
.Pp
.Fn evbuffer_readln
reads and drains a single line from the evbuffer
.Fa buf .
The length of the line will be stored in
.Fa read_out
on success.
It is the responsibility of the caller to free the returned line with
.Xr free 3 .
The line delimiter is specified as one of the following:
.Bl -tag -width xxx -offset indent
.It Dv EVBUFFER_EOL_ANY
Any sequence of newline or carriage return characters.
.It Dv EVBUFFER_EOL_CRLF
A new line optionally preceded by a carriage return.
.It Dv EVBUFFER_EOL_CRLF_STRICT
A carriage return followed by a new line character.
.It Dv EVBUFFER_EOL_LF
A new line character.
.El
.Pp
.Fn EVBUFFER_LENGTH
reports how many bytes are stored in the evbuffer
.Fa buf .
.Sh RETURN VALUES
.Fn evbuffer_new
returns a pointer to a newly allocated buffer on success,
or
.Dv NULL
on failure and sets
.Va errno
to indicate the failure.
.Pp
.Fn evbuffer_expand ,
.Fn evbuffer_add ,
and
.Fn evbuffer_add_buffer
return 0 on success,
or -1 on failure and set
.Va errno
to indicate the failure.
.Pp
.Fn evbuffer_add_printf
and
.Fn evbuffer_add_vprintf
return the number of bytes added on success,
or -1 on failure.
.Pp
.Fn evbuffer_remove
returns the number of bytes read.
.Pp
.Fn evbuffer_write
returns the number of bytes written and drained on success,
or -1 on failure and sets
.Va errno
to indicate the failure.
.Pp
.Fn evbuffer_read
returns the number of bytes appended to the evbuffer on success,
0 on an end of file condition,
or -1 on failure and sets
.Va errno
to indicate the failure.
.Pp
.Fn evbuffer_find
returns a pointer to the start of the string within the evbuffer on success,
or
.Dv NULL
on failure.
.Pp
.Fn evbuffer_readline
and
.Fn evbuffer_readln
return a pointer to the line on success,
or
.Dv NULL
on failure.
.Pp
.Fn EVBUFFER_LENGTH
returns the number of bytes available in the evbuffer.
.Pp
.Fn EVBUFFER_DATA
returns a pointer to the evbuffer
.Fa buf
on success.
.Sh SEE ALSO
.Xr errno 2 ,
.Xr event 3 ,
.Xr free 3 ,
.Xr printf 3
.Sh AUTHORS
The
.Nm event
library was written by
.An Niels Provos .