1 | /* |
1 | /* |
|
|
2 | * libev epoll fd activity backend |
|
|
3 | * |
2 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
3 | * All rights reserved. |
5 | * All rights reserved. |
4 | * |
6 | * |
5 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are |
8 | * modification, are permitted provided that the following conditions are |
… | |
… | |
35 | epoll_modify (int fd, int oev, int nev) |
37 | epoll_modify (int fd, int oev, int nev) |
36 | { |
38 | { |
37 | int mode = nev ? oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD : EPOLL_CTL_DEL; |
39 | int mode = nev ? oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD : EPOLL_CTL_DEL; |
38 | |
40 | |
39 | struct epoll_event ev; |
41 | struct epoll_event ev; |
40 | ev.data.fd = fd; |
42 | ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */ |
41 | ev.events = |
43 | ev.events = |
42 | (nev & EV_READ ? EPOLLIN : 0) |
44 | (nev & EV_READ ? EPOLLIN : 0) |
43 | | (nev & EV_WRITE ? EPOLLOUT : 0); |
45 | | (nev & EV_WRITE ? EPOLLOUT : 0); |
44 | |
46 | |
45 | epoll_ctl (epoll_fd, mode, fd, &ev); |
47 | epoll_ctl (epoll_fd, mode, fd, &ev); |
… | |
… | |
77 | (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
79 | (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
78 | | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) |
80 | | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) |
79 | ); |
81 | ); |
80 | |
82 | |
81 | /* if the receive array was full, increase its size */ |
83 | /* if the receive array was full, increase its size */ |
82 | if (eventcnt == eventmax) |
84 | if (expect_false (eventcnt == eventmax)) |
83 | { |
85 | { |
84 | free (events); |
86 | free (events); |
85 | eventmax += eventmax >> 1; |
87 | eventmax = array_roundsize (events, eventmax << 1); |
86 | events = malloc (sizeof (struct epoll_event) * eventmax); |
88 | events = malloc (sizeof (struct epoll_event) * eventmax); |
87 | } |
89 | } |
88 | } |
90 | } |
89 | |
91 | |
90 | static void |
92 | static void |