Debian Codegraph @

upstream/debian-unstable/man3/sd_event_source_set_ratelimit.3

raw
1 '\" t
2 .TH "SD_EVENT_SOURCE_SET_RATELIMIT" "3" "" "systemd 261~rc3" "sd_event_source_set_ratelimit"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_event_source_set_ratelimit, sd_event_source_get_ratelimit, sd_event_source_is_ratelimited, sd_event_source_set_ratelimit_expire_callback, sd_event_source_leave_ratelimit \- Configure rate limiting on event sources
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-event\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_event_source_set_ratelimit('u
32 .BI "int sd_event_source_set_ratelimit(sd_event_source\ *" "source" ", uint64_t\ " "interval_usec" ", unsigned\ " "burst" ");"
33 .HP \w'int\ sd_event_source_get_ratelimit('u
34 .BI "int sd_event_source_get_ratelimit(sd_event_source\ *" "source" ", uint64_t*\ " "ret_interval_usec" ", unsigned*\ " "ret_burst" ");"
35 .HP \w'int\ sd_event_source_is_ratelimited('u
36 .BI "int sd_event_source_is_ratelimited(sd_event_source\ *" "source" ");"
37 .HP \w'int\ sd_event_source_set_ratelimit_expire_callback('u
38 .BI "int sd_event_source_set_ratelimit_expire_callback(sd_event_source\ *" "source" ", sd_event_handler_t" "callback" ");"
39 .HP \w'int\ sd_event_source_leave_ratelimit('u
40 .BI "int sd_event_source_leave_ratelimit(sd_event_source\ *" "source" ");"
41 .SH "DESCRIPTION"
42 .PP
43 \fBsd_event_source_set_ratelimit()\fR
44 may be used to enforce rate limiting on an event source\&. When used an event source will be temporarily turned off when it fires more often then a specified burst number within a specified time interval\&. This is useful as simple mechanism to avoid event source starvation if high priority event sources fire very frequently\&.
45 .PP
46 Pass the event source to operate on as first argument, a time interval in microseconds as second argument and a maximum dispatch limit ("burst") as third parameter\&. Whenever the event source is dispatched more often than the specified burst within the specified interval it is placed in a mode similar to being disabled with
47 \fBsd_event_source_set_enabled\fR(3)
48 and the
49 \fBSD_EVENT_OFF\fR
50 parameter\&. However, it is disabled only temporarily \(en once the specified interval is over regular operation resumes\&. It is again disabled temporarily once the specified rate limiting is hit the next time\&. If either the interval or the burst value are specified as zero, rate limiting is turned off\&. By default, event sources do not have rate limiting enabled\&. Note that rate limiting and disabling via
51 \fBsd_event_source_set_enabled()\fR
52 are independent of each other, and an event source will only effect event loop wake\-ups and is dispatched while it both is enabled and rate limiting is not in effect\&.
53 .PP
54 \fBsd_event_source_get_ratelimit()\fR
55 may be used to query the current rate limiting parameters set on the event source object
56 \fIsource\fR\&. The previously set interval and burst vales are returned in the second and third argument\&.
57 .PP
58 \fBsd_event_source_is_ratelimited()\fR
59 may be used to query whether the event source is currently affected by rate limiting, i\&.e\&. it has recently hit the rate limit and is currently temporarily disabled due to that\&.
60 .PP
61 \fBsd_event_source_set_ratelimit_expire_callback()\fR
62 may be used to set a callback function that is invoked every time the event source leaves rate limited state\&. Note that function is called in the same event loop iteration in which state transition occurred\&.
63 .PP
64 \fBsd_event_source_leave_ratelimit()\fR
65 may be used to immediately reenable an event source that was temporarily disabled due to rate limiting\&. This will reset the ratelimit counters for the current time interval\&.
66 .PP
67 Rate limiting is currently implemented for I/O, timer, signal, defer and inotify event sources\&.
68 .SH "RETURN VALUE"
69 .PP
70 On success,
71 \fBsd_event_source_set_ratelimit()\fR,
72 \fBsd_event_source_set_ratelimit_expire_callback\fR
73 and
74 \fBsd_event_source_get_ratelimit()\fR
75 return a non\-negative integer\&. On failure, they return a negative errno\-style error code\&.
76 \fBsd_event_source_is_ratelimited()\fR
77 returns zero if rate limiting is currently not in effect and greater than zero if it is in effect; it returns a negative errno\-style error code on failure\&.
78 \fBsd_event_source_leave_ratelimit()\fR
79 returns zero if rate limiting was not in effect on the specified event source, and positive if it was and rate limiting is now turned off again; it returns a negative errno\-style error code on failure\&.
80 .SS "Errors"
81 .PP
82 Returned errors may indicate the following problems:
83 .PP
84 \fB\-EINVAL\fR
85 .RS 4
86 \fIsource\fR
87 is not a valid pointer to an
88 sd_event_source
89 object\&.
90 .sp
91 Added in version 248\&.
92 .RE
93 .PP
94 \fB\-ECHILD\fR
95 .RS 4
96 The event loop has been created in a different process, library or module instance\&.
97 .sp
98 Added in version 248\&.
99 .RE
100 .PP
101 \fB\-EDOM\fR
102 .RS 4
103 It was attempted to use the rate limiting feature on an event source type that does not support rate limiting\&.
104 .sp
105 Added in version 248\&.
106 .RE
107 .PP
108 \fB\-ENOEXEC\fR
109 .RS 4
110 \fBsd_event_source_get_ratelimit()\fR
111 was called on an event source that does not have rate limiting configured\&.
112 .sp
113 Added in version 248\&.
114 .RE
115 .SH "NOTES"
116 .PP
117 Functions described here are available as a shared library, which can be compiled against and linked to with the
118 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
119 file\&.
120 .PP
121 The code described here uses
122 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
123 \fBsetenv\fR(3)
124 from a parallel thread\&. It is recommended to only do calls to
125 \fBsetenv()\fR
126 from an early phase of the program when no other threads have been started\&.
127 .SH "HISTORY"
128 .PP
129 \fBsd_event_source_set_ratelimit()\fR,
130 \fBsd_event_source_get_ratelimit()\fR, and
131 \fBsd_event_source_is_ratelimited()\fR
132 were added in version 248\&.
133 .PP
134 \fBsd_event_source_set_ratelimit_expire_callback()\fR
135 was added in version 250\&.
136 .PP
137 \fBsd_event_source_leave_ratelimit()\fR
138 was added in version 254\&.
139 .SH "SEE ALSO"
140 .PP
141 \fBsd-event\fR(3), \fBsd_event_add_io\fR(3), \fBsd_event_add_time\fR(3), \fBsd_event_add_signal\fR(3), \fBsd_event_add_inotify\fR(3), \fBsd_event_add_defer\fR(3), \fBsd_event_source_set_enabled\fR(3)