The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* http://frotznet.googlecode.com/svn/trunk/utils/fdevent.c |
| 2 | ** |
| 3 | ** Copyright 2006, Brian Swetland <swetland@frotz.net> |
| 4 | ** |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 8 | ** |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 10 | ** |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Yabin Cui | aed3c61 | 2015-09-22 15:52:57 -0700 | [diff] [blame] | 18 | #define TRACE_TAG FDEVENT |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 19 | |
Dan Albert | 3313426 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 20 | #include "sysdeps.h" |
| 21 | #include "fdevent.h" |
| 22 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 23 | #include <fcntl.h> |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 24 | #include <poll.h> |
Dan Albert | 3313426 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <sys/ioctl.h> |
| 28 | #include <unistd.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 29 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 30 | #include <list> |
| 31 | #include <unordered_map> |
| 32 | #include <vector> |
| 33 | |
| 34 | #include <base/logging.h> |
| 35 | #include <base/stringprintf.h> |
| 36 | |
Dan Albert | cc731cc | 2015-02-24 21:26:58 -0800 | [diff] [blame] | 37 | #include "adb_io.h" |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 38 | #include "adb_trace.h" |
Yabin Cui | 6dfef25 | 2015-10-06 15:10:05 -0700 | [diff] [blame] | 39 | #include "adb_utils.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 40 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 41 | #if !ADB_HOST |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 42 | // This socket is used when a subproc shell service exists. |
| 43 | // It wakes up the fdevent_loop() and cause the correct handling |
| 44 | // of the shell's pseudo-tty master. I.e. force close it. |
| 45 | int SHELL_EXIT_NOTIFY_FD = -1; |
Alex Vallée | 947cb3e | 2015-07-17 15:30:59 -0400 | [diff] [blame] | 46 | #endif // !ADB_HOST |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 47 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 | #define FDE_EVENTMASK 0x00ff |
| 49 | #define FDE_STATEMASK 0xff00 |
| 50 | |
| 51 | #define FDE_ACTIVE 0x0100 |
| 52 | #define FDE_PENDING 0x0200 |
| 53 | #define FDE_CREATED 0x0400 |
| 54 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 55 | struct PollNode { |
| 56 | fdevent* fde; |
| 57 | pollfd pollfd; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 58 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 59 | PollNode(fdevent* fde) : fde(fde) { |
| 60 | memset(&pollfd, 0, sizeof(pollfd)); |
| 61 | pollfd.fd = fde->fd; |
Yabin Cui | aa77e22 | 2015-09-29 12:25:33 -0700 | [diff] [blame] | 62 | |
| 63 | #if defined(__linux__) |
| 64 | // Always enable POLLRDHUP, so the host server can take action when some clients disconnect. |
| 65 | // Then we can avoid leaving many sockets in CLOSE_WAIT state. See http://b/23314034. |
| 66 | pollfd.events = POLLRDHUP; |
| 67 | #endif |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 68 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 71 | // All operations to fdevent should happen only in the main thread. |
| 72 | // That's why we don't need a lock for fdevent. |
| 73 | static std::unordered_map<int, PollNode> g_poll_node_map; |
| 74 | static std::list<fdevent*> g_pending_list; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 75 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 76 | static std::string dump_fde(const fdevent* fde) { |
| 77 | std::string state; |
| 78 | if (fde->state & FDE_ACTIVE) { |
| 79 | state += "A"; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 80 | } |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 81 | if (fde->state & FDE_PENDING) { |
| 82 | state += "P"; |
| 83 | } |
| 84 | if (fde->state & FDE_CREATED) { |
| 85 | state += "C"; |
| 86 | } |
| 87 | if (fde->state & FDE_READ) { |
| 88 | state += "R"; |
| 89 | } |
| 90 | if (fde->state & FDE_WRITE) { |
| 91 | state += "W"; |
| 92 | } |
| 93 | if (fde->state & FDE_ERROR) { |
| 94 | state += "E"; |
| 95 | } |
| 96 | if (fde->state & FDE_DONT_CLOSE) { |
| 97 | state += "D"; |
| 98 | } |
| 99 | return android::base::StringPrintf("(fdevent %d %s)", fde->fd, state.c_str()); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 100 | } |
| 101 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 102 | fdevent *fdevent_create(int fd, fd_func func, void *arg) |
| 103 | { |
| 104 | fdevent *fde = (fdevent*) malloc(sizeof(fdevent)); |
| 105 | if(fde == 0) return 0; |
| 106 | fdevent_install(fde, fd, func, arg); |
| 107 | fde->state |= FDE_CREATED; |
| 108 | return fde; |
| 109 | } |
| 110 | |
| 111 | void fdevent_destroy(fdevent *fde) |
| 112 | { |
| 113 | if(fde == 0) return; |
| 114 | if(!(fde->state & FDE_CREATED)) { |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 115 | LOG(FATAL) << "destroying fde not created by fdevent_create(): " << dump_fde(fde); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 116 | } |
| 117 | fdevent_remove(fde); |
SungHyun Kwon | abb80e0 | 2015-03-03 13:56:42 +0900 | [diff] [blame] | 118 | free(fde); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 121 | void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) { |
| 122 | CHECK_GE(fd, 0); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 123 | memset(fde, 0, sizeof(fdevent)); |
| 124 | fde->state = FDE_ACTIVE; |
| 125 | fde->fd = fd; |
| 126 | fde->func = func; |
| 127 | fde->arg = arg; |
Yabin Cui | 6dfef25 | 2015-10-06 15:10:05 -0700 | [diff] [blame] | 128 | if (!set_file_block_mode(fd, false)) { |
Yabin Cui | c1b1f6f | 2015-09-15 16:27:09 -0700 | [diff] [blame] | 129 | // Here is not proper to handle the error. If it fails here, some error is |
| 130 | // likely to be detected by poll(), then we can let the callback function |
| 131 | // to handle it. |
Yabin Cui | 6dfef25 | 2015-10-06 15:10:05 -0700 | [diff] [blame] | 132 | LOG(ERROR) << "failed to set non-blocking mode for fd " << fd; |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 133 | } |
| 134 | auto pair = g_poll_node_map.emplace(fde->fd, PollNode(fde)); |
| 135 | CHECK(pair.second) << "install existing fd " << fd; |
| 136 | D("fdevent_install %s", dump_fde(fde).c_str()); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 139 | void fdevent_remove(fdevent* fde) { |
| 140 | D("fdevent_remove %s", dump_fde(fde).c_str()); |
| 141 | if (fde->state & FDE_ACTIVE) { |
| 142 | g_poll_node_map.erase(fde->fd); |
| 143 | if (fde->state & FDE_PENDING) { |
| 144 | g_pending_list.remove(fde); |
| 145 | } |
| 146 | if (!(fde->state & FDE_DONT_CLOSE)) { |
| 147 | adb_close(fde->fd); |
| 148 | fde->fd = -1; |
| 149 | } |
| 150 | fde->state = 0; |
| 151 | fde->events = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 152 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 155 | static void fdevent_update(fdevent* fde, unsigned events) { |
| 156 | auto it = g_poll_node_map.find(fde->fd); |
| 157 | CHECK(it != g_poll_node_map.end()); |
| 158 | PollNode& node = it->second; |
| 159 | if (events & FDE_READ) { |
| 160 | node.pollfd.events |= POLLIN; |
| 161 | } else { |
| 162 | node.pollfd.events &= ~POLLIN; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 165 | if (events & FDE_WRITE) { |
| 166 | node.pollfd.events |= POLLOUT; |
| 167 | } else { |
| 168 | node.pollfd.events &= ~POLLOUT; |
| 169 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 170 | fde->state = (fde->state & FDE_STATEMASK) | events; |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 171 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 172 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 173 | void fdevent_set(fdevent* fde, unsigned events) { |
| 174 | events &= FDE_EVENTMASK; |
| 175 | if ((fde->state & FDE_EVENTMASK) == events) { |
| 176 | return; |
| 177 | } |
Spencer Low | 888a748 | 2015-09-29 18:33:38 -0700 | [diff] [blame] | 178 | CHECK(fde->state & FDE_ACTIVE); |
| 179 | fdevent_update(fde, events); |
| 180 | D("fdevent_set: %s, events = %u", dump_fde(fde).c_str(), events); |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 181 | |
Spencer Low | 888a748 | 2015-09-29 18:33:38 -0700 | [diff] [blame] | 182 | if (fde->state & FDE_PENDING) { |
| 183 | // If we are pending, make sure we don't signal an event that is no longer wanted. |
| 184 | fde->events &= events; |
| 185 | if (fde->events == 0) { |
| 186 | g_pending_list.remove(fde); |
| 187 | fde->state &= ~FDE_PENDING; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 192 | void fdevent_add(fdevent* fde, unsigned events) { |
| 193 | fdevent_set(fde, (fde->state & FDE_EVENTMASK) | events); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 196 | void fdevent_del(fdevent* fde, unsigned events) { |
| 197 | fdevent_set(fde, (fde->state & FDE_EVENTMASK) & ~events); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 200 | static std::string dump_pollfds(const std::vector<pollfd>& pollfds) { |
| 201 | std::string result; |
Elliott Hughes | 65fe251 | 2015-10-07 15:59:35 -0700 | [diff] [blame] | 202 | for (const auto& pollfd : pollfds) { |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 203 | std::string op; |
| 204 | if (pollfd.events & POLLIN) { |
| 205 | op += "R"; |
| 206 | } |
| 207 | if (pollfd.events & POLLOUT) { |
| 208 | op += "W"; |
| 209 | } |
| 210 | android::base::StringAppendF(&result, " %d(%s)", pollfd.fd, op.c_str()); |
| 211 | } |
| 212 | return result; |
| 213 | } |
| 214 | |
| 215 | static void fdevent_process() { |
| 216 | std::vector<pollfd> pollfds; |
Elliott Hughes | 65fe251 | 2015-10-07 15:59:35 -0700 | [diff] [blame] | 217 | for (const auto& pair : g_poll_node_map) { |
| 218 | pollfds.push_back(pair.second.pollfd); |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 219 | } |
| 220 | CHECK_GT(pollfds.size(), 0u); |
| 221 | D("poll(), pollfds = %s", dump_pollfds(pollfds).c_str()); |
| 222 | int ret = TEMP_FAILURE_RETRY(poll(&pollfds[0], pollfds.size(), -1)); |
| 223 | if (ret == -1) { |
Yabin Cui | c1b1f6f | 2015-09-15 16:27:09 -0700 | [diff] [blame] | 224 | PLOG(ERROR) << "poll(), ret = " << ret; |
| 225 | return; |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 226 | } |
Elliott Hughes | 65fe251 | 2015-10-07 15:59:35 -0700 | [diff] [blame] | 227 | for (const auto& pollfd : pollfds) { |
Yabin Cui | c1b1f6f | 2015-09-15 16:27:09 -0700 | [diff] [blame] | 228 | if (pollfd.revents != 0) { |
| 229 | D("for fd %d, revents = %x", pollfd.fd, pollfd.revents); |
| 230 | } |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 231 | unsigned events = 0; |
| 232 | if (pollfd.revents & POLLIN) { |
| 233 | events |= FDE_READ; |
| 234 | } |
| 235 | if (pollfd.revents & POLLOUT) { |
| 236 | events |= FDE_WRITE; |
| 237 | } |
| 238 | if (pollfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { |
| 239 | // We fake a read, as the rest of the code assumes that errors will |
| 240 | // be detected at that point. |
| 241 | events |= FDE_READ | FDE_ERROR; |
| 242 | } |
Yabin Cui | aa77e22 | 2015-09-29 12:25:33 -0700 | [diff] [blame] | 243 | #if defined(__linux__) |
| 244 | if (pollfd.revents & POLLRDHUP) { |
| 245 | events |= FDE_READ | FDE_ERROR; |
| 246 | } |
| 247 | #endif |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 248 | if (events != 0) { |
| 249 | auto it = g_poll_node_map.find(pollfd.fd); |
| 250 | CHECK(it != g_poll_node_map.end()); |
| 251 | fdevent* fde = it->second.fde; |
| 252 | CHECK_EQ(fde->fd, pollfd.fd); |
| 253 | fde->events |= events; |
| 254 | D("%s got events %x", dump_fde(fde).c_str(), events); |
| 255 | fde->state |= FDE_PENDING; |
| 256 | g_pending_list.push_back(fde); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | static void fdevent_call_fdfunc(fdevent* fde) |
| 262 | { |
| 263 | unsigned events = fde->events; |
| 264 | fde->events = 0; |
Spencer Low | 888a748 | 2015-09-29 18:33:38 -0700 | [diff] [blame] | 265 | CHECK(fde->state & FDE_PENDING); |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 266 | fde->state &= (~FDE_PENDING); |
| 267 | D("fdevent_call_fdfunc %s", dump_fde(fde).c_str()); |
| 268 | fde->func(fde->fd, events, fde->arg); |
| 269 | } |
| 270 | |
| 271 | #if !ADB_HOST |
| 272 | static void fdevent_subproc_event_func(int fd, unsigned ev, |
| 273 | void* /* userdata */) |
| 274 | { |
| 275 | |
| 276 | D("subproc handling on fd = %d, ev = %x", fd, ev); |
| 277 | |
| 278 | CHECK_GE(fd, 0); |
| 279 | |
| 280 | if (ev & FDE_READ) { |
| 281 | int subproc_fd; |
| 282 | |
| 283 | if(!ReadFdExactly(fd, &subproc_fd, sizeof(subproc_fd))) { |
| 284 | LOG(FATAL) << "Failed to read the subproc's fd from " << fd; |
| 285 | } |
| 286 | auto it = g_poll_node_map.find(subproc_fd); |
| 287 | if (it == g_poll_node_map.end()) { |
| 288 | D("subproc_fd %d cleared from fd_table", subproc_fd); |
| 289 | return; |
| 290 | } |
| 291 | fdevent* subproc_fde = it->second.fde; |
| 292 | if(subproc_fde->fd != subproc_fd) { |
| 293 | // Already reallocated? |
| 294 | D("subproc_fd(%d) != subproc_fde->fd(%d)", subproc_fd, subproc_fde->fd); |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | subproc_fde->force_eof = 1; |
| 299 | |
| 300 | int rcount = 0; |
| 301 | ioctl(subproc_fd, FIONREAD, &rcount); |
| 302 | D("subproc with fd %d has rcount=%d, err=%d", subproc_fd, rcount, errno); |
| 303 | if (rcount != 0) { |
| 304 | // If there is data left, it will show up in the select(). |
| 305 | // This works because there is no other thread reading that |
| 306 | // data when in this fd_func(). |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | D("subproc_fde %s", dump_fde(subproc_fde).c_str()); |
| 311 | subproc_fde->events |= FDE_READ; |
| 312 | if(subproc_fde->state & FDE_PENDING) { |
| 313 | return; |
| 314 | } |
| 315 | subproc_fde->state |= FDE_PENDING; |
| 316 | fdevent_call_fdfunc(subproc_fde); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | void fdevent_subproc_setup() |
| 321 | { |
| 322 | int s[2]; |
| 323 | |
| 324 | if(adb_socketpair(s)) { |
| 325 | PLOG(FATAL) << "cannot create shell-exit socket-pair"; |
| 326 | } |
| 327 | D("fdevent_subproc: socket pair (%d, %d)", s[0], s[1]); |
| 328 | |
| 329 | SHELL_EXIT_NOTIFY_FD = s[0]; |
| 330 | fdevent *fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL); |
| 331 | CHECK(fde != nullptr) << "cannot create fdevent for shell-exit handler"; |
| 332 | fdevent_add(fde, FDE_READ); |
| 333 | } |
| 334 | #endif // !ADB_HOST |
| 335 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 336 | void fdevent_loop() |
| 337 | { |
Alex Vallée | 947cb3e | 2015-07-17 15:30:59 -0400 | [diff] [blame] | 338 | #if !ADB_HOST |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 339 | fdevent_subproc_setup(); |
Alex Vallée | 947cb3e | 2015-07-17 15:30:59 -0400 | [diff] [blame] | 340 | #endif // !ADB_HOST |
David 'Digit' Turner | f6330a2 | 2009-05-18 17:36:28 +0200 | [diff] [blame] | 341 | |
Elliott Hughes | aa24549 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 342 | while (true) { |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 343 | D("--- --- waiting for events"); |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 344 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 345 | fdevent_process(); |
David 'Digit' Turner | f6330a2 | 2009-05-18 17:36:28 +0200 | [diff] [blame] | 346 | |
Yabin Cui | a108016 | 2015-09-04 16:19:56 -0700 | [diff] [blame] | 347 | while (!g_pending_list.empty()) { |
| 348 | fdevent* fde = g_pending_list.front(); |
| 349 | g_pending_list.pop_front(); |
JP Abgrall | 408fa57 | 2011-03-16 15:57:42 -0700 | [diff] [blame] | 350 | fdevent_call_fdfunc(fde); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | } |
Yabin Cui | c1b1f6f | 2015-09-15 16:27:09 -0700 | [diff] [blame] | 354 | |
| 355 | size_t fdevent_installed_count() { |
| 356 | return g_poll_node_map.size(); |
| 357 | } |
| 358 | |
| 359 | void fdevent_reset() { |
| 360 | g_poll_node_map.clear(); |
| 361 | g_pending_list.clear(); |
| 362 | } |