1 | /* |
1 | /* |
2 | * libev kqueue backend |
2 | * libev kqueue backend |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010 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 | * |
… | |
… | |
115 | { |
115 | { |
116 | int fd = kqueue_events [i].ident; |
116 | int fd = kqueue_events [i].ident; |
117 | |
117 | |
118 | if (expect_false (kqueue_events [i].flags & EV_ERROR)) |
118 | if (expect_false (kqueue_events [i].flags & EV_ERROR)) |
119 | { |
119 | { |
120 | int err = kqueue_events [i].data; |
120 | int err = kqueue_events [i].data; |
121 | |
121 | |
122 | /* we are only interested in errors for fds that we are interested in :) */ |
122 | /* we are only interested in errors for fds that we are interested in :) */ |
123 | if (anfds [fd].events) |
123 | if (anfds [fd].events) |
124 | { |
124 | { |
125 | if (err == ENOENT) /* resubmit changes on ENOENT */ |
125 | if (err == ENOENT) /* resubmit changes on ENOENT */ |
126 | kqueue_modify (EV_A_ fd, 0, anfds [fd].events); |
126 | kqueue_modify (EV_A_ fd, 0, anfds [fd].events); |
127 | else if (err == EBADF) /* on EBADF, we re-check the fd */ |
127 | else if (err == EBADF) /* on EBADF, we re-check the fd */ |
128 | { |
128 | { |
129 | if (fd_valid (fd)) |
129 | if (fd_valid (fd)) |
… | |
… | |
131 | else |
131 | else |
132 | fd_kill (EV_A_ fd); |
132 | fd_kill (EV_A_ fd); |
133 | } |
133 | } |
134 | else /* on all other errors, we error out on the fd */ |
134 | else /* on all other errors, we error out on the fd */ |
135 | fd_kill (EV_A_ fd); |
135 | fd_kill (EV_A_ fd); |
136 | } |
136 | } |
137 | } |
137 | } |
138 | else |
138 | else |
139 | fd_event ( |
139 | fd_event ( |
140 | EV_A_ |
140 | EV_A_ |
141 | fd, |
141 | fd, |
… | |
… | |
154 | } |
154 | } |
155 | |
155 | |
156 | int inline_size |
156 | int inline_size |
157 | kqueue_init (EV_P_ int flags) |
157 | kqueue_init (EV_P_ int flags) |
158 | { |
158 | { |
159 | /* Initalize the kernel queue */ |
159 | /* Initialize the kernel queue */ |
160 | if ((backend_fd = kqueue ()) < 0) |
160 | if ((backend_fd = kqueue ()) < 0) |
161 | return 0; |
161 | return 0; |
162 | |
162 | |
163 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ |
163 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ |
164 | |
164 | |