-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbufferevent_enable.3
131 lines (131 loc) · 3.6 KB
/
bufferevent_enable.3
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
.\" $OpenBSD$
.\" Copyright (c) 2023 Ted Bullock <tbullock@comlore.com>
.\"
.\" 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$
.Dt BUFFEREVENT_ENABLE 3
.Os
.Sh NAME
.Nm bufferevent_enable ,
.Nm bufferevent_disable
.Nd control bufferevent scheduling
.Sh SYNOPSIS
.In event.h
.Ft int
.Fn bufferevent_enable "struct bufferevent *bufev" "short event"
.Ft int
.Fn bufferevent_disable "struct bufferevent *bufev" "short event"
.Sh DESCRIPTION
These functions manage the state of a
.Vt bufferevent
structure
.Fa bufev
by controlling its transition between
.Em initialized
and
.Em scheduled
states for either read or write operations independently.
The
.Fa event
parameter decides the type of event operation to be scheduled or unscheduled,
which can be
.Dv EV_READ ,
.Dv EV_WRITE ,
or a combination of both
.Pq Dv EV_READ | Dv EV_WRITE .
Values of
.Fa event
other than these are undefined.
If
.Fa bufev
is
.Dv NULL
the behavior is undefined.
.Pp
.Fn bufferevent_enable
transitions
.Fa bufev
from an initialized state to a scheduled state.
The function shares the same failure conditions as
.Xr event_add 3 .
.Pp
Conversely,
.Fn bufferevent_disable
transitions
.Fa bufev
from a scheduled state back to an initialized state.
The function shares the same failure conditions as
.Xr event_del 3 .
.Sh RETURN VALUES
These functions return 0 on success or \-1 on failure.
.Pp
Some failure conditions do not return; refer to the
.Xr event_add 3
manual page for documentation on this behavior.
.Sh ERRORS
Although they do not set
.Va errno
directly on failure, these functions preserve
.Va errno
values set within internal calls to
.Xr event_add 3
and
.Xr event_del 3
respectively.
.Sh SEE ALSO
.Xr bufferevent_new 3 ,
.Xr event_add 3 ,
.Xr event_del 3
.Sh HISTORY
These functions first appeared in libevent-0.8 and have been available since
.Ox 3.6 .
.Sh AUTHORS
.Fn bufferevent_enable
and
.Fn bufferevent_disable
were written by
.An -nosplit
.An Niels Provos .
.Pp
This manual page was written by
.An Ted Bullock Aq Mt tbullock@comlore.com .
.Sh CAVEATS
Although these functions inherit the failure conditions of
.Xr event_add 3
and
.Xr event_del 3 ,
this behavior is not part of the API contract and newer versions of libevent
have different behavior.
.Sh BUGS
In cases where the function is called with
.Ql EV_READ | EV_WRITE
and one of the event scheduling operations fails, the functions return \-1,
indicating an overall failure.
However, one of the event operations may have been successfully scheduled or
unscheduled, without providing an explicit indication to the caller.
.Pp
To ensure reliable error handling, it is recommended to separate the function
calls for each event type.
Instead of using
.Ql EV_READ | EV_WRITE
in a single function call, perform separate calls for
.Dv EV_READ
and
.Dv EV_WRITE .
.Pp
For example:
.Dl "bufferevent_enable(bufev, EV_READ);"
.Dl "bufferevent_enable(bufev, EV_WRITE);"
.Pp
This allows the caller to handle the failure of each operation independently.