.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "IO::Epoll 3pm" .TH IO::Epoll 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME IO::Epoll \- Scalable IO Multiplexing for Linux 2.5.44 and higher .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& # Low level interface \& use IO::Epoll; \& \& $epfd = epoll_create(10); \& \& epoll_ctl($epfd, EPOLL_CTL_ADD, fileno STDIN, EPOLLIN) >= 0 \& || die "epoll_ctl: $!\en"; \& epoll_ctl($epfd, ...); \& \& $events = epoll_wait($epfd, 10, 1000); # Max 10 events returned, 1s timeout \& \& # High level IO::Poll emulation layer \& use IO::EPoll qw(:compat); \& \& $poll = new IO::Epoll; \& \& $poll\->mask($input_handle => POLLIN); \& $poll\->mask($output_handle => POLLOUT); \& \& $poll\->poll($timeout); \& \& $ev = $poll\->events($input); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" The \f(CWepoll(4)\fR subsystem is a new, (currently) Linux-specific variant of \&\f(CWpoll(2)\fR. It is designed to offer O(1) scalability over large numbers of watched file descriptors. You will need at least version 2.5.44 of Linux to use this module, and you might need to upgrade your C library. .PP The \f(CWepoll(2)\fR API comprises four system calls: \f(CWepoll_create(2)\fR, \&\f(CWepoll_ctl(2)\fR, \f(CWepoll_wait(2)\fR and \f(CWepoll_pwait(2)\fR. \f(CW\*(C`IO::Epoll\*(C'\fR provides a low-level API which closely matches the underlying system calls. It also provides a higher-level layer designed to emulate the behavior of \&\f(CW\*(C`IO::Poll\*(C'\fR and \f(CW\*(C`IO::Ppoll\*(C'\fR. .SH "LOW-LEVEL API" .IX Header "LOW-LEVEL API" .SS epoll_create .IX Subsection "epoll_create" Create a new \f(CW\*(C`epoll\*(C'\fR file descriptor by requesting the kernel allocate an event backing store dimensioned for \f(CW\*(C`size\*(C'\fR descriptors. The size is not the maximum size of the backing store but just a hint to the kernel about how to dimension internal structures. The returned file descriptor will be used for all the subsequent calls to the \f(CW\*(C`epoll\*(C'\fR interface. The file descriptor returned by \&\f(CW\*(C`epoll_create\*(C'\fR must be closed by using \f(CW\*(C`POSIX::close\*(C'\fR. .PP .Vb 3 \& $epfd = epoll_create(15); \& ... \& POSIX::close($epfd); .Ve .PP When successful, \f(CW\*(C`epoll_create\*(C'\fR returns a positive integer identifying the descriptor. When an error occurs, \f(CW\*(C`epoll_create\*(C'\fR returns \-1 and errno is set appropriately. .SS epoll_ctl .IX Subsection "epoll_ctl" Control an \f(CW\*(C`epoll\*(C'\fR descriptor, \f(CW$epfd\fR, by requesting the operation op be performed on the target file descriptor, fd. .PP .Vb 1 \& $ret = epoll_ctl($epfd, $op, $fd, $eventmask) .Ve .PP \&\f(CW$epfd\fR is an \f(CW\*(C`epoll\*(C'\fR descriptor returned from \f(CW\*(C`epoll_create\*(C'\fR. .PP \&\f(CW$op\fR is one of \f(CW\*(C`EPOLL_CTL_ADD\*(C'\fR, \f(CW\*(C`EPOLL_CTL_MOD\*(C'\fR or \f(CW\*(C`EPOLL_CTL_DEL\*(C'\fR. .PP \&\f(CW$fd\fR is the file desciptor to be watched. .PP \&\f(CW$eventmask\fR is a bitmask of events defined by \f(CW\*(C`EPOLLIN\*(C'\fR, \f(CW\*(C`EPOLLOUT\*(C'\fR, etc. .PP When successful, \f(CW\*(C`epoll_ctl\*(C'\fR returns 0. When an error occurs, \&\f(CW\*(C`epoll_ctl\*(C'\fR returns \-1 and errno is set appropriately. .SS epoll_wait .IX Subsection "epoll_wait" Wait for events on the \f(CW\*(C`epoll\*(C'\fR file descriptor \f(CW$epfd\fR. .PP .Vb 1 \& $ret = epoll_wait($epfd, $maxevents, $timeout) .Ve .PP \&\f(CW$epfd\fR is an \f(CW\*(C`epoll\*(C'\fR descriptor returned from \f(CW\*(C`epoll_create\*(C'\fR. .PP \&\f(CW$maxevents\fR is an integer specifying the maximum number of events to be returned. .PP \&\f(CW$timeout\fR is a timeout, in milliseconds .PP When successful, \f(CW\*(C`epoll_wait\*(C'\fR returns a reference to an array of events. Each event is a two element array, the first element being the file descriptor which triggered the event, and the second is the mask of event types triggered. For example, if \f(CW\*(C`epoll_wait\*(C'\fR returned the following data structure: .PP .Vb 4 \& [ \& [ 0, EPOLLIN ], \& [ 6, EPOLLOUT | EPOLLIN ] \& ] .Ve .PP then file descriptor 0 would be ready for reading, and fd 4 would be ready for both reading and writing. .PP On error, \f(CW\*(C`epoll_wait\*(C'\fR returns undef and sets \f(CW\*(C`errno\*(C'\fR appropriately. .SS epoll_pwait .IX Subsection "epoll_pwait" Wait for events on the \f(CW\*(C`epoll\*(C'\fR file descriptor \f(CW$epfd\fR. .PP .Vb 1 \& $ret = epoll_pwait($epfd, $maxevents, $timeout, $sigmask) .Ve .PP Identical to \f(CW\*(C`epoll_wait\*(C'\fR, except that the kernel will atomically swap the current signal mask for the process to that supplied in \f(CW$sigmask\fR, wait for events, then restore it to what it was originally. The \f(CW$sigmask\fR parameter should be undef, or an instance of \f(CW\*(C`POSIX::SigSet\*(C'\fR. .SH "HIGH LEVEL API" .IX Header "HIGH LEVEL API" IO::Epoll provides an object oriented API designed to be a drop-in replacement for IO::Poll. See the documentation for that module for more information. .SH METHODS .IX Header "METHODS" .IP "mask ( IO [, EVENT_MASK ] )" 4 .IX Item "mask ( IO [, EVENT_MASK ] )" If EVENT_MASK is given, then, if EVENT_MASK is non-zero, IO is added to the list of file descriptors and the next call to poll will check for any event specified in EVENT_MASK. If EVENT_MASK is zero then IO will be removed from the list of file descriptors. .Sp If EVENT_MASK is not given then the return value will be the current event mask value for IO. .IP "poll ( [ TIMEOUT ] )" 4 .IX Item "poll ( [ TIMEOUT ] )" Call the system level poll routine. If TIMEOUT is not specified then the call will block. Returns the number of handles which had events happen, or \-1 on error. TIMEOUT is in seconds and may be fractional. .IP "events ( IO )" 4 .IX Item "events ( IO )" Returns the event mask which represents the events that happend on IO during the last call to \f(CW\*(C`poll\*(C'\fR. .IP "remove ( IO )" 4 .IX Item "remove ( IO )" Remove IO from the list of file descriptors for the next poll. .IP "handles( [ EVENT_MASK ] )" 4 .IX Item "handles( [ EVENT_MASK ] )" Returns a list of handles. If EVENT_MASK is not given then a list of all handles known will be returned. If EVENT_MASK is given then a list of handles will be returned which had one of the events specified by EVENT_MASK happen during the last call ti \f(CW\*(C`poll\*(C'\fR .SH "IO::Ppoll METHODS" .IX Header "IO::Ppoll METHODS" IO::Epoll also provides methods compatible with IO::Ppoll. When any of these methods are called, the IO::Epoll object switches up to IO::Ppoll\-compatible mode, and will use the \f(CWepoll_pwait(2)\fR system call when the \f(CW\*(C`poll\*(C'\fR method is invoked. .IP sigmask 4 .IX Item "sigmask" Returns the \f(CW\*(C`POSIX::SigSet\*(C'\fR object in which the signal mask is stored. Since this is a reference to the object used in the call to \f(CWepoll_pwait(2)\fR, any modifications made to it will be reflected in the signal mask given to the system call. .IP "sigmask_add ( SIGNALS )" 4 .IX Item "sigmask_add ( SIGNALS )" Adds the given signals to the signal mask. These signals will be blocked during the \f(CW\*(C`poll\*(C'\fR call. .IP "sigmask_del ( SIGNALS )" 4 .IX Item "sigmask_del ( SIGNALS )" Removes the given signals from the signal mask. These signals will not be blocked during the \f(CW\*(C`poll\*(C'\fR call, and may be delivered while \f(CW\*(C`poll\*(C'\fR is waiting. .IP "sigmask_ismember ( SIGNAL )" 4 .IX Item "sigmask_ismember ( SIGNAL )" Tests if the given signal is present in the signal mask. .SH "Exportable constants" .IX Header "Exportable constants" Exported by default: .PP .Vb 10 \& EPOLLERR \& EPOLLET \& EPOLLHUP \& EPOLLIN \& EPOLLMSG \& EPOLLOUT \& EPOLLPRI \& EPOLLRDBAND \& EPOLLRDNORM \& EPOLLWRBAND \& EPOLLWRNORM \& EPOLL_CTL_ADD \& EPOLL_CTL_DEL \& EPOLL_CTL_MOD .Ve .PP Exported by the :compat tag: .PP .Vb 10 \& POLLNVAL \& POLLIN \& POLLOUT \& POLLERR \& POLLHUP \& POLLPRI \& POLLRDNORM \& POLLWRNORM \& POLLRDBAND \& POLLWRBAND .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" \&\f(CW\*(C`IO::Poll\*(C'\fR \f(CW\*(C`IO::Select\*(C'\fR \f(CW\*(C`IO::Ppoll\*(C'\fR \f(CWepoll(4)\fR \f(CWepoll_create(2)\fR \&\f(CWepoll_ctl(2)\fR \f(CWepoll_wait(2)\fR \f(CWepoll_pwait(2)\fR .SH AUTHOR .IX Header "AUTHOR" Bruce J Keeler, .SH CREDITS .IX Header "CREDITS" The \f(CW\*(C`IO::Poll\*(C'\fR compatibility code borrows heavily from the \f(CW\*(C`IO::Poll\*(C'\fR code itself, which was written by Graham Barr. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2004 by Bruce J. Keeler Portions Copyright (C) 1997\-8 Graham Barr .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.