ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_epoll.c
(Generate patch)

Comparing libev/ev_epoll.c (file contents):
Revision 1.70 by root, Mon Oct 12 17:53:17 2015 UTC vs.
Revision 1.75 by root, Tue Jun 25 16:43:52 2019 UTC

1/* 1/*
2 * libev epoll fd activity backend 2 * libev epoll fd activity backend
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2016,2017,2019 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
122 anfds [fd].emask = EV_EMASK_EPERM; 122 anfds [fd].emask = EV_EMASK_EPERM;
123 123
124 /* add fd to epoll_eperms, if not already inside */ 124 /* add fd to epoll_eperms, if not already inside */
125 if (!(oldmask & EV_EMASK_EPERM)) 125 if (!(oldmask & EV_EMASK_EPERM))
126 { 126 {
127 array_needsize (int, epoll_eperms, epoll_epermmax, epoll_epermcnt + 1, EMPTY2); 127 array_needsize (int, epoll_eperms, epoll_epermmax, epoll_epermcnt + 1, array_needsize_noinit);
128 epoll_eperms [epoll_epermcnt++] = fd; 128 epoll_eperms [epoll_epermcnt++] = fd;
129 } 129 }
130 130
131 return; 131 return;
132 } 132 }
233 anfds [fd].emask = 0; 233 anfds [fd].emask = 0;
234 } 234 }
235 } 235 }
236} 236}
237 237
238static int
239epoll_epoll_create (void)
240{
241 int fd;
242
243#if defined EPOLL_CLOEXEC && !defined __ANDROID__
244 fd = epoll_create1 (EPOLL_CLOEXEC);
245
246 if (fd < 0 && (errno == EINVAL || errno == ENOSYS))
247#endif
248 {
249 fd = epoll_create (256);
250
251 if (fd >= 0)
252 fcntl (fd, F_SETFD, FD_CLOEXEC);
253 }
254
255 return fd;
256}
257
238int inline_size 258inline_size
259int
239epoll_init (EV_P_ int flags) 260epoll_init (EV_P_ int flags)
240{ 261{
241#ifdef EPOLL_CLOEXEC 262 if ((backend_fd = epoll_epoll_create ()) < 0)
242 backend_fd = epoll_create1 (EPOLL_CLOEXEC);
243
244 if (backend_fd < 0 && (errno == EINVAL || errno == ENOSYS))
245#endif
246 backend_fd = epoll_create (256);
247
248 if (backend_fd < 0)
249 return 0; 263 return 0;
250
251 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
252 264
253 backend_mintime = 1e-3; /* epoll does sometimes return early, this is just to avoid the worst */ 265 backend_mintime = 1e-3; /* epoll does sometimes return early, this is just to avoid the worst */
254 backend_modify = epoll_modify; 266 backend_modify = epoll_modify;
255 backend_poll = epoll_poll; 267 backend_poll = epoll_poll;
256 268
258 epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax); 270 epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
259 271
260 return EVBACKEND_EPOLL; 272 return EVBACKEND_EPOLL;
261} 273}
262 274
263void inline_size 275inline_size
276void
264epoll_destroy (EV_P) 277epoll_destroy (EV_P)
265{ 278{
266 ev_free (epoll_events); 279 ev_free (epoll_events);
267 array_free (epoll_eperm, EMPTY); 280 array_free (epoll_eperm, EMPTY);
268} 281}
269 282
270void inline_size 283inline_size
284void
271epoll_fork (EV_P) 285epoll_fork (EV_P)
272{ 286{
273 close (backend_fd); 287 close (backend_fd);
274 288
275 while ((backend_fd = epoll_create (256)) < 0) 289 while ((backend_fd = epoll_epoll_create ()) < 0)
276 ev_syserr ("(libev) epoll_create"); 290 ev_syserr ("(libev) epoll_create");
277 291
278 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
279
280 fd_rearm_all (EV_A); 292 fd_rearm_all (EV_A);
281} 293}
282 294

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines