4 * Select abstraction functions for the CUPS scheduler.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 2006-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
23 # include <sys/epoll.h>
25 #elif defined(HAVE_KQUEUE)
26 # include <sys/event.h>
27 # include <sys/time.h>
28 #elif defined(HAVE_POLL)
31 # include <sys/select.h>
32 #endif /* HAVE_EPOLL */
36 * Design Notes for Poll/Select API in CUPSD
37 * -----------------------------------------
41 * OS select poll epoll kqueue /dev/poll
42 * -------------- ------ ------ ------ ------ ---------
43 * AIX YES YES NO NO NO
44 * FreeBSD YES YES NO YES NO
45 * HP-UX YES YES NO NO NO
46 * Linux YES YES YES NO NO
47 * MacOS X YES YES NO YES NO
48 * NetBSD YES YES NO YES NO
49 * OpenBSD YES YES NO YES NO
50 * Solaris YES YES NO NO YES
51 * Tru64 YES YES NO NO NO
52 * Windows YES NO NO NO NO
57 * typedef void (*cupsd_selfunc_t)(void *data);
59 * void cupsdStartSelect(void);
60 * void cupsdStopSelect(void);
61 * void cupsdAddSelect(int fd, cupsd_selfunc_t read_cb,
62 * cupsd_selfunc_t write_cb, void *data);
63 * void cupsdRemoveSelect(int fd);
64 * int cupsdDoSelect(int timeout);
67 * IMPLEMENTATION STRATEGY
70 * a. CUPS array of file descriptor to callback functions
71 * and data + temporary array of removed fd's.
72 * b. cupsdStartSelect() creates the arrays
73 * c. cupsdStopSelect() destroys the arrays and all elements.
74 * d. cupsdAddSelect() adds to the array and allocates a
75 * new callback element.
76 * e. cupsdRemoveSelect() removes from the active array and
77 * adds to the inactive array.
78 * f. _cupsd_fd_t provides a reference-counted structure for
79 * tracking file descriptors that are monitored.
80 * g. cupsdDoSelect() frees all inactive FDs.
83 * a. Input/Output fd_set variables, copied to working
84 * copies and then used with select().
85 * b. Loop through CUPS array, using FD_ISSET and calling
86 * the read/write callbacks as needed.
87 * c. cupsdRemoveSelect() clears fd_set bit from main and
89 * d. cupsdStopSelect() frees all of the memory used by the
90 * CUPS array and fd_set's.
92 * 2. poll() - O(n log n)
93 * a. Regular array of pollfd, sorted the same as the CUPS
95 * b. Loop through pollfd array, call the corresponding
96 * read/write callbacks as needed.
97 * c. cupsdAddSelect() adds first to CUPS array and flags the
98 * pollfd array as invalid.
99 * d. cupsdDoSelect() rebuilds pollfd array as needed, calls
100 * poll(), then loops through the pollfd array looking up
102 * e. cupsdRemoveSelect() flags the pollfd array as invalid.
103 * f. cupsdStopSelect() frees all of the memory used by the
104 * CUPS array and pollfd array.
107 * a. cupsdStartSelect() creates epoll file descriptor using
108 * epoll_create() with the maximum fd count, and
109 * allocates an events buffer for the maximum fd count.
110 * b. cupsdAdd/RemoveSelect() uses epoll_ctl() to add
111 * (EPOLL_CTL_ADD) or remove (EPOLL_CTL_DEL) a single
112 * event using the level-triggered semantics. The event
113 * user data field is a pointer to the new callback array
115 * c. cupsdDoSelect() uses epoll_wait() with the global event
116 * buffer allocated in cupsdStartSelect() and then loops
117 * through the events, using the user data field to find
118 * the callback record.
119 * d. cupsdStopSelect() closes the epoll file descriptor and
120 * frees all of the memory used by the event buffer.
123 * b. cupsdStartSelect() creates kqueue file descriptor
124 * using kqueue() function and allocates a global event
126 * c. cupsdAdd/RemoveSelect() uses EV_SET and kevent() to
127 * register the changes. The event user data field is a
128 * pointer to the new callback array element.
129 * d. cupsdDoSelect() uses kevent() to poll for events and
130 * loops through the events, using the user data field to
131 * find the callback record.
132 * e. cupsdStopSelect() closes the kqueue() file descriptor
133 * and frees all of the memory used by the event buffer.
135 * 5. /dev/poll - O(n log n) - NOT YET IMPLEMENTED
136 * a. cupsdStartSelect() opens /dev/poll and allocates an
137 * array of pollfd structs; on failure to open /dev/poll,
138 * revert to poll() system call.
139 * b. cupsdAddSelect() writes a single pollfd struct to
140 * /dev/poll with the new file descriptor and the
141 * POLLIN/POLLOUT flags.
142 * c. cupsdRemoveSelect() writes a single pollfd struct to
143 * /dev/poll with the file descriptor and the POLLREMOVE
145 * d. cupsdDoSelect() uses the DP_POLL ioctl to retrieve
146 * events from /dev/poll and then loops through the
147 * returned pollfd array, looking up the file descriptors
149 * e. cupsdStopSelect() closes /dev/poll and frees the
154 * In tests using the "make test" target with option 0 (keep cupsd
155 * running) and the "testspeed" program with "-c 50 -r 1000", epoll()
156 * performed 5.5% slower than select(), followed by kqueue() at 16%
157 * slower than select() and poll() at 18% slower than select(). Similar
158 * results were seen with twice the number of client connections.
160 * The epoll() and kqueue() performance is likely limited by the
161 * number of system calls used to add/modify/remove file
162 * descriptors dynamically. Further optimizations may be possible
163 * in the area of limiting use of cupsdAddSelect() and
164 * cupsdRemoveSelect(), however extreme care will be needed to avoid
165 * excess CPU usage and deadlock conditions.
167 * We may be able to improve the poll() implementation simply by
168 * keeping the pollfd array sync'd with the _cupsd_fd_t array, as that
169 * will eliminate the rebuilding of the array whenever there is a
170 * change and eliminate the fd array lookups in the inner loop of
173 * Since /dev/poll will never be able to use a shadow array, it may
174 * not make sense to implement support for it. ioctl() overhead will
175 * impact performance as well, so my guess would be that, for CUPS,
176 * /dev/poll will yield a net performance loss.
180 * Local structures...
183 typedef struct _cupsd_fd_s
185 int fd
, /* File descriptor */
187 cupsd_selfunc_t read_cb
, /* Read callback */
188 write_cb
; /* Write callback */
189 void *data
; /* Data pointer for callbacks */
197 static cups_array_t
*cupsd_fds
= NULL
;
198 #if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)
199 static cups_array_t
*cupsd_inactive_fds
= NULL
;
200 static int cupsd_in_select
= 0;
201 #endif /* HAVE_EPOLL || HAVE_KQUEUE */
204 static int cupsd_kqueue_fd
= -1,
205 cupsd_kqueue_changes
= 0;
206 static struct kevent
*cupsd_kqueue_events
= NULL
;
207 #elif defined(HAVE_POLL)
208 static int cupsd_alloc_pollfds
= 0,
209 cupsd_update_pollfds
= 0;
210 static struct pollfd
*cupsd_pollfds
= NULL
;
212 static int cupsd_epoll_fd
= -1;
213 static struct epoll_event
*cupsd_epoll_events
= NULL
;
214 # endif /* HAVE_EPOLL */
216 static fd_set cupsd_global_input
,
219 cupsd_current_output
;
220 #endif /* HAVE_KQUEUE */
227 static int compare_fds(_cupsd_fd_t
*a
, _cupsd_fd_t
*b
);
228 static _cupsd_fd_t
*find_fd(int fd
);
229 #define release_fd(f) { \
231 if (!(f)->use) free((f));\
233 #define retain_fd(f) (f)->use++
237 * 'cupsdAddSelect()' - Add a file descriptor to the list.
240 int /* O - 1 on success, 0 on error */
241 cupsdAddSelect(int fd
, /* I - File descriptor */
242 cupsd_selfunc_t read_cb
, /* I - Read callback */
243 cupsd_selfunc_t write_cb
,/* I - Write callback */
244 void *data
) /* I - Data to pass to callback */
246 _cupsd_fd_t
*fdptr
; /* File descriptor record */
248 int added
; /* 1 if added, 0 if modified */
249 #endif /* HAVE_EPOLL */
253 * Range check input...
256 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
257 "cupsdAddSelect(fd=%d, read_cb=%p, write_cb=%p, data=%p)",
258 fd
, read_cb
, write_cb
, data
);
264 * See if this FD has already been added...
267 if ((fdptr
= find_fd(fd
)) == NULL
)
270 * No, add a new entry...
273 if ((fdptr
= calloc(1, sizeof(_cupsd_fd_t
))) == NULL
)
279 if (!cupsArrayAdd(cupsd_fds
, fdptr
))
281 cupsdLogMessage(CUPSD_LOG_EMERG
, "Unable to add fd %d to array!", fd
);
293 #endif /* HAVE_EPOLL */
297 struct kevent event
; /* Event data */
298 struct timespec timeout
; /* Timeout value */
304 if (fdptr
->read_cb
!= read_cb
)
307 EV_SET(&event
, fd
, EVFILT_READ
, EV_ADD
, 0, 0, fdptr
);
309 EV_SET(&event
, fd
, EVFILT_READ
, EV_DELETE
, 0, 0, fdptr
);
311 if (kevent(cupsd_kqueue_fd
, &event
, 1, NULL
, 0, &timeout
))
313 cupsdLogMessage(CUPSD_LOG_EMERG
, "kevent() returned %s",
319 if (fdptr
->write_cb
!= write_cb
)
322 EV_SET(&event
, fd
, EVFILT_WRITE
, EV_ADD
, 0, 0, fdptr
);
324 EV_SET(&event
, fd
, EVFILT_WRITE
, EV_DELETE
, 0, 0, fdptr
);
326 if (kevent(cupsd_kqueue_fd
, &event
, 1, NULL
, 0, &timeout
))
328 cupsdLogMessage(CUPSD_LOG_EMERG
, "kevent() returned %s",
335 #elif defined(HAVE_POLL)
337 if (cupsd_epoll_fd
>= 0)
339 struct epoll_event event
; /* Event data */
345 event
.events
|= EPOLLIN
;
348 event
.events
|= EPOLLOUT
;
350 event
.data
.ptr
= fdptr
;
352 if (epoll_ctl(cupsd_epoll_fd
, added
? EPOLL_CTL_ADD
: EPOLL_CTL_MOD
, fd
,
355 close(cupsd_epoll_fd
);
357 cupsd_update_pollfds
= 1;
361 # endif /* HAVE_EPOLL */
363 cupsd_update_pollfds
= 1;
367 * Add or remove the file descriptor in the input and output sets
372 FD_SET(fd
, &cupsd_global_input
);
375 FD_CLR(fd
, &cupsd_global_input
);
376 FD_CLR(fd
, &cupsd_current_input
);
380 FD_SET(fd
, &cupsd_global_output
);
383 FD_CLR(fd
, &cupsd_global_output
);
384 FD_CLR(fd
, &cupsd_current_output
);
386 #endif /* HAVE_KQUEUE */
389 * Save the (new) read and write callbacks...
392 fdptr
->read_cb
= read_cb
;
393 fdptr
->write_cb
= write_cb
;
401 * 'cupsdDoSelect()' - Do a select-like operation.
404 int /* O - Number of files or -1 on error */
405 cupsdDoSelect(long timeout
) /* I - Timeout in seconds */
407 int nfds
; /* Number of file descriptors */
408 _cupsd_fd_t
*fdptr
; /* Current file descriptor */
410 int i
; /* Looping var */
411 struct kevent
*event
; /* Current event */
412 struct timespec ktimeout
; /* kevent() timeout */
417 if (timeout
>= 0 && timeout
< 86400)
419 ktimeout
.tv_sec
= timeout
;
420 ktimeout
.tv_nsec
= 0;
422 nfds
= kevent(cupsd_kqueue_fd
, NULL
, 0, cupsd_kqueue_events
, MaxFDs
,
426 nfds
= kevent(cupsd_kqueue_fd
, NULL
, 0, cupsd_kqueue_events
, MaxFDs
, NULL
);
428 cupsd_kqueue_changes
= 0;
430 for (i
= nfds
, event
= cupsd_kqueue_events
; i
> 0; i
--, event
++)
432 fdptr
= (_cupsd_fd_t
*)event
->udata
;
434 if (cupsArrayFind(cupsd_inactive_fds
, fdptr
))
439 if (fdptr
->read_cb
&& event
->filter
== EVFILT_READ
)
440 (*(fdptr
->read_cb
))(fdptr
->data
);
442 if (fdptr
->use
> 1 && fdptr
->write_cb
&& event
->filter
== EVFILT_WRITE
&&
443 !cupsArrayFind(cupsd_inactive_fds
, fdptr
))
444 (*(fdptr
->write_cb
))(fdptr
->data
);
449 #elif defined(HAVE_POLL)
450 struct pollfd
*pfd
; /* Current pollfd structure */
451 int count
; /* Number of file descriptors */
457 if (cupsd_epoll_fd
>= 0)
459 int i
; /* Looping var */
460 struct epoll_event
*event
; /* Current event */
463 if (timeout
>= 0 && timeout
< 86400)
464 nfds
= epoll_wait(cupsd_epoll_fd
, cupsd_epoll_events
, MaxFDs
,
467 nfds
= epoll_wait(cupsd_epoll_fd
, cupsd_epoll_events
, MaxFDs
, -1);
469 if (nfds
< 0 && errno
!= EINTR
)
471 close(cupsd_epoll_fd
);
476 for (i
= nfds
, event
= cupsd_epoll_events
; i
> 0; i
--, event
++)
478 fdptr
= (_cupsd_fd_t
*)event
->data
.ptr
;
480 if (cupsArrayFind(cupsd_inactive_fds
, fdptr
))
485 if (fdptr
->read_cb
&& (event
->events
& (EPOLLIN
| EPOLLERR
| EPOLLHUP
)))
486 (*(fdptr
->read_cb
))(fdptr
->data
);
488 if (fdptr
->use
> 1 && fdptr
->write_cb
&&
489 (event
->events
& (EPOLLOUT
| EPOLLERR
| EPOLLHUP
)) &&
490 !cupsArrayFind(cupsd_inactive_fds
, fdptr
))
491 (*(fdptr
->write_cb
))(fdptr
->data
);
496 goto release_inactive
;
499 # endif /* HAVE_EPOLL */
501 count
= cupsArrayCount(cupsd_fds
);
503 if (cupsd_update_pollfds
)
506 * Update the cupsd_pollfds array to match the current FD array...
509 cupsd_update_pollfds
= 0;
512 * (Re)allocate memory as needed...
515 if (count
> cupsd_alloc_pollfds
)
517 int allocfds
= count
+ 16;
521 pfd
= realloc(cupsd_pollfds
, (size_t)allocfds
* sizeof(struct pollfd
));
523 pfd
= malloc((size_t)allocfds
* sizeof(struct pollfd
));
527 cupsdLogMessage(CUPSD_LOG_EMERG
, "Unable to allocate %d bytes for polling.", (int)((size_t)allocfds
* sizeof(struct pollfd
)));
533 cupsd_alloc_pollfds
= allocfds
;
537 * Rebuild the array...
540 for (fdptr
= (_cupsd_fd_t
*)cupsArrayFirst(cupsd_fds
), pfd
= cupsd_pollfds
;
542 fdptr
= (_cupsd_fd_t
*)cupsArrayNext(cupsd_fds
), pfd
++)
548 pfd
->events
|= POLLIN
;
551 pfd
->events
|= POLLOUT
;
555 if (timeout
>= 0 && timeout
< 86400)
556 nfds
= poll(cupsd_pollfds
, (nfds_t
)count
, timeout
* 1000);
558 nfds
= poll(cupsd_pollfds
, (nfds_t
)count
, -1);
563 * Do callbacks for each file descriptor...
566 for (pfd
= cupsd_pollfds
; count
> 0; pfd
++, count
--)
571 if ((fdptr
= find_fd(pfd
->fd
)) == NULL
)
576 if (fdptr
->read_cb
&& (pfd
->revents
& (POLLIN
| POLLERR
| POLLHUP
)))
577 (*(fdptr
->read_cb
))(fdptr
->data
);
579 if (fdptr
->use
> 1 && fdptr
->write_cb
&&
580 (pfd
->revents
& (POLLOUT
| POLLERR
| POLLHUP
)))
581 (*(fdptr
->write_cb
))(fdptr
->data
);
588 struct timeval stimeout
; /* Timeout for select() */
589 int maxfd
; /* Maximum file descriptor */
593 * Figure out the highest file descriptor number...
596 if ((fdptr
= (_cupsd_fd_t
*)cupsArrayLast(cupsd_fds
)) == NULL
)
599 maxfd
= fdptr
->fd
+ 1;
605 cupsd_current_input
= cupsd_global_input
;
606 cupsd_current_output
= cupsd_global_output
;
608 if (timeout
>= 0 && timeout
< 86400)
610 stimeout
.tv_sec
= timeout
;
611 stimeout
.tv_usec
= 0;
613 nfds
= select(maxfd
, &cupsd_current_input
, &cupsd_current_output
, NULL
,
617 nfds
= select(maxfd
, &cupsd_current_input
, &cupsd_current_output
, NULL
,
623 * Do callbacks for each file descriptor...
626 for (fdptr
= (_cupsd_fd_t
*)cupsArrayFirst(cupsd_fds
);
628 fdptr
= (_cupsd_fd_t
*)cupsArrayNext(cupsd_fds
))
632 if (fdptr
->read_cb
&& FD_ISSET(fdptr
->fd
, &cupsd_current_input
))
633 (*(fdptr
->read_cb
))(fdptr
->data
);
635 if (fdptr
->use
> 1 && fdptr
->write_cb
&&
636 FD_ISSET(fdptr
->fd
, &cupsd_current_output
))
637 (*(fdptr
->write_cb
))(fdptr
->data
);
643 #endif /* HAVE_KQUEUE */
645 #if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)
647 * Release all inactive file descriptors...
652 # endif /* !HAVE_KQUEUE */
656 for (fdptr
= (_cupsd_fd_t
*)cupsArrayFirst(cupsd_inactive_fds
);
658 fdptr
= (_cupsd_fd_t
*)cupsArrayNext(cupsd_inactive_fds
))
660 cupsArrayRemove(cupsd_inactive_fds
, fdptr
);
663 #endif /* HAVE_EPOLL || HAVE_KQUEUE */
666 * Return the number of file descriptors handled...
673 #ifdef CUPSD_IS_SELECTING
675 * 'cupsdIsSelecting()' - Determine whether we are monitoring a file
679 int /* O - 1 if selecting, 0 otherwise */
680 cupsdIsSelecting(int fd
) /* I - File descriptor */
682 return (find_fd(fd
) != NULL
);
684 #endif /* CUPSD_IS_SELECTING */
688 * 'cupsdRemoveSelect()' - Remove a file descriptor from the list.
692 cupsdRemoveSelect(int fd
) /* I - File descriptor */
694 _cupsd_fd_t
*fdptr
; /* File descriptor record */
696 struct epoll_event event
; /* Event data */
697 #elif defined(HAVE_KQUEUE)
698 struct kevent event
; /* Event data */
699 struct timespec timeout
; /* Timeout value */
700 #elif defined(HAVE_POLL)
701 /* No variables for poll() */
702 #endif /* HAVE_EPOLL */
706 * Range check input...
709 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdRemoveSelect(fd=%d)", fd
);
715 * Find the file descriptor...
718 if ((fdptr
= find_fd(fd
)) == NULL
)
722 if (epoll_ctl(cupsd_epoll_fd
, EPOLL_CTL_DEL
, fd
, &event
))
724 close(cupsd_epoll_fd
);
726 cupsd_update_pollfds
= 1;
729 #elif defined(HAVE_KQUEUE)
735 EV_SET(&event
, fd
, EVFILT_READ
, EV_DELETE
, 0, 0, fdptr
);
737 if (kevent(cupsd_kqueue_fd
, &event
, 1, NULL
, 0, &timeout
))
739 cupsdLogMessage(CUPSD_LOG_EMERG
, "kevent() returned %s",
747 EV_SET(&event
, fd
, EVFILT_WRITE
, EV_DELETE
, 0, 0, fdptr
);
749 if (kevent(cupsd_kqueue_fd
, &event
, 1, NULL
, 0, &timeout
))
751 cupsdLogMessage(CUPSD_LOG_EMERG
, "kevent() returned %s",
757 #elif defined(HAVE_POLL)
759 * Update the pollfds array...
762 cupsd_update_pollfds
= 1;
765 FD_CLR(fd
, &cupsd_global_input
);
766 FD_CLR(fd
, &cupsd_global_output
);
767 FD_CLR(fd
, &cupsd_current_input
);
768 FD_CLR(fd
, &cupsd_current_output
);
769 #endif /* HAVE_EPOLL */
773 #endif /* HAVE_KQUEUE */
776 * Remove the file descriptor from the active array and add to the
777 * inactive array (or release, if we don't need the inactive array...)
780 cupsArrayRemove(cupsd_fds
, fdptr
);
782 #if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)
784 cupsArrayAdd(cupsd_inactive_fds
, fdptr
);
786 #endif /* HAVE_EPOLL || HAVE_KQUEUE */
793 * 'cupsdStartSelect()' - Initialize the file polling engine.
797 cupsdStartSelect(void)
799 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdStartSelect()");
801 cupsd_fds
= cupsArrayNew((cups_array_func_t
)compare_fds
, NULL
);
803 #if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)
804 cupsd_inactive_fds
= cupsArrayNew((cups_array_func_t
)compare_fds
, NULL
);
805 #endif /* HAVE_EPOLL || HAVE_KQUEUE */
808 cupsd_epoll_fd
= epoll_create(MaxFDs
);
809 cupsd_epoll_events
= calloc((size_t)MaxFDs
, sizeof(struct epoll_event
));
810 cupsd_update_pollfds
= 0;
812 #elif defined(HAVE_KQUEUE)
813 cupsd_kqueue_fd
= kqueue();
814 cupsd_kqueue_changes
= 0;
815 cupsd_kqueue_events
= calloc((size_t)MaxFDs
, sizeof(struct kevent
));
817 #elif defined(HAVE_POLL)
818 cupsd_update_pollfds
= 0;
821 FD_ZERO(&cupsd_global_input
);
822 FD_ZERO(&cupsd_global_output
);
823 #endif /* HAVE_EPOLL */
828 * 'cupsdStopSelect()' - Shutdown the file polling engine.
832 cupsdStopSelect(void)
834 _cupsd_fd_t
*fdptr
; /* Current file descriptor */
837 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdStopSelect()");
839 for (fdptr
= (_cupsd_fd_t
*)cupsArrayFirst(cupsd_fds
);
841 fdptr
= (_cupsd_fd_t
*)cupsArrayNext(cupsd_fds
))
844 cupsArrayDelete(cupsd_fds
);
847 #if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE)
848 cupsArrayDelete(cupsd_inactive_fds
);
849 cupsd_inactive_fds
= NULL
;
850 #endif /* HAVE_EPOLL || HAVE_KQUEUE */
853 if (cupsd_kqueue_events
)
855 free(cupsd_kqueue_events
);
856 cupsd_kqueue_events
= NULL
;
859 if (cupsd_kqueue_fd
>= 0)
861 close(cupsd_kqueue_fd
);
862 cupsd_kqueue_fd
= -1;
865 cupsd_kqueue_changes
= 0;
867 #elif defined(HAVE_POLL)
869 if (cupsd_epoll_events
)
871 free(cupsd_epoll_events
);
872 cupsd_epoll_events
= NULL
;
875 if (cupsd_epoll_fd
>= 0)
877 close(cupsd_epoll_fd
);
880 # endif /* HAVE_EPOLL */
885 cupsd_pollfds
= NULL
;
886 cupsd_alloc_pollfds
= 0;
889 cupsd_update_pollfds
= 0;
892 FD_ZERO(&cupsd_global_input
);
893 FD_ZERO(&cupsd_global_output
);
894 #endif /* HAVE_EPOLL */
899 * 'compare_fds()' - Compare file descriptors.
902 static int /* O - Result of comparison */
903 compare_fds(_cupsd_fd_t
*a
, /* I - First file descriptor */
904 _cupsd_fd_t
*b
) /* I - Second file descriptor */
906 return (a
->fd
- b
->fd
);
911 * 'find_fd()' - Find an existing file descriptor record.
914 static _cupsd_fd_t
* /* O - FD record pointer or NULL */
915 find_fd(int fd
) /* I - File descriptor */
917 _cupsd_fd_t
*fdptr
, /* Matching record (if any) */
918 key
; /* Search key */
921 cupsArraySave(cupsd_fds
);
924 fdptr
= (_cupsd_fd_t
*)cupsArrayFind(cupsd_fds
, &key
);
926 cupsArrayRestore(cupsd_fds
);