Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: third_party/libevent/epoll.c

Issue 118126: Linux: stop libevent from pre-allocating huge arrays. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2000-2003 Niels Provos <provos@citi.umich.edu> 2 * Copyright 2000-2003 Niels Provos <provos@citi.umich.edu>
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 #ifdef HAVE_SETFD 88 #ifdef HAVE_SETFD
89 #define FD_CLOSEONEXEC(x) do { \ 89 #define FD_CLOSEONEXEC(x) do { \
90 if (fcntl(x, F_SETFD, 1) == -1) \ 90 if (fcntl(x, F_SETFD, 1) == -1) \
91 event_warn("fcntl(%d, F_SETFD)", x); \ 91 event_warn("fcntl(%d, F_SETFD)", x); \
92 } while (0) 92 } while (0)
93 #else 93 #else
94 #define FD_CLOSEONEXEC(x) 94 #define FD_CLOSEONEXEC(x)
95 #endif 95 #endif
96 96
97 #define NEVENT» 32000 97 #define NEVENT» 32
98 98
99 /* On Linux kernels at least up to 2.6.24.4, epoll can't handle timeout 99 /* On Linux kernels at least up to 2.6.24.4, epoll can't handle timeout
100 * values bigger than (LONG_MAX - 999ULL)/HZ. HZ in the wild can be 100 * values bigger than (LONG_MAX - 999ULL)/HZ. HZ in the wild can be
101 * as big as 1000, and LONG_MAX can be as small as (1<<31)-1, so the 101 * as big as 1000, and LONG_MAX can be as small as (1<<31)-1, so the
102 * largest number of msec we can support here is 2147482. Let's 102 * largest number of msec we can support here is 2147482. Let's
103 * round that down by 47 seconds. 103 * round that down by 47 seconds.
104 */ 104 */
105 #define MAX_EPOLL_TIMEOUT_MSEC (35*60*1000) 105 #define MAX_EPOLL_TIMEOUT_MSEC (35*60*1000)
106 106
107 static void * 107 static void *
108 epoll_init(struct event_base *base) 108 epoll_init(struct event_base *base)
109 { 109 {
110 int epfd, nfiles = NEVENT; 110 int epfd, nfiles = NEVENT;
111 struct rlimit rl; 111 struct rlimit rl;
112 struct epollop *epollop; 112 struct epollop *epollop;
113 113
114 /* Disable epollueue when this environment variable is set */ 114 /* Disable epollueue when this environment variable is set */
115 if (getenv("EVENT_NOEPOLL")) 115 if (getenv("EVENT_NOEPOLL"))
116 return (NULL); 116 return (NULL);
117 117
118 if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
119 rl.rlim_cur != RLIM_INFINITY) {
120 /*
121 * Solaris is somewhat retarded - it's important to drop
122 * backwards compatibility when making changes. So, don't
123 * dare to put rl.rlim_cur here.
124 */
125 nfiles = rl.rlim_cur - 1;
126 }
127
128 /* Initalize the kernel queue */ 118 /* Initalize the kernel queue */
129 119
130 if ((epfd = epoll_create(nfiles)) == -1) { 120 if ((epfd = epoll_create(nfiles)) == -1) {
131 if (errno != ENOSYS) 121 if (errno != ENOSYS)
132 event_warn("epoll_create"); 122 event_warn("epoll_create");
133 return (NULL); 123 return (NULL);
134 } 124 }
135 125
136 FD_CLOSEONEXEC(epfd); 126 FD_CLOSEONEXEC(epfd);
137 127
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 evsignal_process(base); 209 evsignal_process(base);
220 } 210 }
221 211
222 event_debug(("%s: epoll_wait reports %d", __func__, res)); 212 event_debug(("%s: epoll_wait reports %d", __func__, res));
223 213
224 for (i = 0; i < res; i++) { 214 for (i = 0; i < res; i++) {
225 int what = events[i].events; 215 int what = events[i].events;
226 struct event *evread = NULL, *evwrite = NULL; 216 struct event *evread = NULL, *evwrite = NULL;
227 int fd = events[i].data.fd; 217 int fd = events[i].data.fd;
228 218
229 » » if (fd < 0 && fd >= epollop->nfds) 219 » » if (fd < 0 || fd >= epollop->nfds)
230 continue; 220 continue;
231 evep = &epollop->fds[fd]; 221 evep = &epollop->fds[fd];
232 222
233 if (what & (EPOLLHUP|EPOLLERR)) { 223 if (what & (EPOLLHUP|EPOLLERR)) {
234 evread = evep->evread; 224 evread = evep->evread;
235 evwrite = evep->evwrite; 225 evwrite = evep->evwrite;
236 } else { 226 } else {
237 if (what & EPOLLIN) { 227 if (what & EPOLLIN) {
238 evread = evep->evread; 228 evread = evep->evread;
239 } 229 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if (epollop->fds) 354 if (epollop->fds)
365 free(epollop->fds); 355 free(epollop->fds);
366 if (epollop->events) 356 if (epollop->events)
367 free(epollop->events); 357 free(epollop->events);
368 if (epollop->epfd >= 0) 358 if (epollop->epfd >= 0)
369 close(epollop->epfd); 359 close(epollop->epfd);
370 360
371 memset(epollop, 0, sizeof(struct epollop)); 361 memset(epollop, 0, sizeof(struct epollop));
372 free(epollop); 362 free(epollop);
373 } 363 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698