'\" t .TH "SD_EVENT_SOURCE_SET_RATELIMIT" "3" "" "systemd 256.6" "sd_event_source_set_ratelimit" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" 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 .SH "SYNOPSIS" .sp .ft B .nf #include .fi .ft .HP \w'int\ sd_event_source_set_ratelimit('u .BI "int sd_event_source_set_ratelimit(sd_event_source\ *" "source" ", uint64_t\ " "interval_usec" ", unsigned\ " "burst" ");" .HP \w'int\ sd_event_source_get_ratelimit('u .BI "int sd_event_source_get_ratelimit(sd_event_source\ *" "source" ", uint64_t*\ " "ret_interval_usec" ", unsigned*\ " "ret_burst" ");" .HP \w'int\ sd_event_source_is_ratelimited('u .BI "int sd_event_source_is_ratelimited(sd_event_source\ *" "source" ");" .HP \w'int\ sd_event_source_set_ratelimit_expire_callback('u .BI "int sd_event_source_set_ratelimit_expire_callback(sd_event_source\ *" "source" ", sd_event_handler_t" "callback" ");" .HP \w'int\ sd_event_source_leave_ratelimit('u .BI "int sd_event_source_leave_ratelimit(sd_event_source\ *" "source" ");" .SH "DESCRIPTION" .PP \fBsd_event_source_set_ratelimit()\fR 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\&. .PP 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 \fBsd_event_source_set_enabled\fR(3) and the \fBSD_EVENT_OFF\fR 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 \fBsd_event_source_set_enabled()\fR 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\&. .PP \fBsd_event_source_get_ratelimit()\fR may be used to query the current rate limiting parameters set on the event source object \fIsource\fR\&. The previously set interval and burst vales are returned in the second and third argument\&. .PP \fBsd_event_source_is_ratelimited()\fR 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\&. .PP \fBsd_event_source_set_ratelimit_expire_callback()\fR 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\&. .PP \fBsd_event_source_leave_ratelimit()\fR 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\&. .PP Rate limiting is currently implemented for I/O, timer, signal, defer and inotify event sources\&. .SH "RETURN VALUE" .PP On success, \fBsd_event_source_set_ratelimit()\fR, \fBsd_event_source_set_ratelimit_expire_callback\fR and \fBsd_event_source_get_ratelimit()\fR return a non\-negative integer\&. On failure, they return a negative errno\-style error code\&. \fBsd_event_source_is_ratelimited()\fR 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\&. \fBsd_event_source_leave_ratelimit()\fR returns zero if rate limiting wasn\*(Aqt 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\&. .SS "Errors" .PP Returned errors may indicate the following problems: .PP \fB\-EINVAL\fR .RS 4 \fIsource\fR is not a valid pointer to an sd_event_source object\&. .sp Added in version 248\&. .RE .PP \fB\-ECHILD\fR .RS 4 The event loop has been created in a different process, library or module instance\&. .sp Added in version 248\&. .RE .PP \fB\-EDOM\fR .RS 4 It was attempted to use the rate limiting feature on an event source type that does not support rate limiting\&. .sp Added in version 248\&. .RE .PP \fB\-ENOEXEC\fR .RS 4 \fBsd_event_source_get_ratelimit()\fR was called on an event source that doesn\*(Aqt have rate limiting configured\&. .sp Added in version 248\&. .RE .SH "NOTES" .PP Functions described here are available as a shared library, which can be compiled against and linked to with the \fBlibsystemd\fR\ \&\fBpkg-config\fR(1) file\&. .PP The code described here uses \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 \fBsetenv\fR(3) from a parallel thread\&. It is recommended to only do calls to \fBsetenv()\fR from an early phase of the program when no other threads have been started\&. .SH "HISTORY" .PP \fBsd_event_source_set_ratelimit()\fR, \fBsd_event_source_get_ratelimit()\fR, and \fBsd_event_source_is_ratelimited()\fR were added in version 248\&. .PP \fBsd_event_source_set_ratelimit_expire_callback()\fR was added in version 250\&. .PP \fBsd_event_source_leave_ratelimit()\fR was added in version 254\&. .SH "SEE ALSO" .PP \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)