OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #if defined(FLETCH_TARGET_OS_LINUX) | 5 #if defined(DARTINO_TARGET_OS_LINUX) |
6 | 6 |
7 #include "src/vm/event_handler.h" | 7 #include "src/vm/event_handler.h" |
8 | 8 |
9 #include <sys/epoll.h> | 9 #include <sys/epoll.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <fcntl.h> | 11 #include <fcntl.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "src/shared/utils.h" | 14 #include "src/shared/utils.h" |
15 #include "src/vm/thread.h" | 15 #include "src/vm/thread.h" |
16 #include "src/vm/object.h" | 16 #include "src/vm/object.h" |
17 #include "src/vm/process.h" | 17 #include "src/vm/process.h" |
18 | 18 |
19 // Some versions of android sys/epoll does not define | 19 // Some versions of android sys/epoll does not define |
20 // EPOLLRDHUP. However, it works as intended, so we just | 20 // EPOLLRDHUP. However, it works as intended, so we just |
21 // define it if it is not there. | 21 // define it if it is not there. |
22 #if !defined(EPOLLRDHUP) | 22 #if !defined(EPOLLRDHUP) |
23 #define EPOLLRDHUP 0x2000 | 23 #define EPOLLRDHUP 0x2000 |
24 #endif // !defined(EPOLLRDHUP) | 24 #endif // !defined(EPOLLRDHUP) |
25 | 25 |
26 namespace fletch { | 26 namespace dartino { |
27 | 27 |
28 void EventHandler::Create() { | 28 void EventHandler::Create() { |
29 int* fds = new int[2]; | 29 int* fds = new int[2]; |
30 if (pipe(fds) != 0) FATAL("Failed to start the event handler pipe\n"); | 30 if (pipe(fds) != 0) FATAL("Failed to start the event handler pipe\n"); |
31 int status = fcntl(fds[0], F_SETFD, FD_CLOEXEC); | 31 int status = fcntl(fds[0], F_SETFD, FD_CLOEXEC); |
32 if (status == -1) FATAL("Failed making read pipe close on exec."); | 32 if (status == -1) FATAL("Failed making read pipe close on exec."); |
33 status = fcntl(fds[1], F_SETFD, FD_CLOEXEC); | 33 status = fcntl(fds[1], F_SETFD, FD_CLOEXEC); |
34 if (status == -1) FATAL("Failed making write pipe close on exec."); | 34 if (status == -1) FATAL("Failed making write pipe close on exec."); |
35 | 35 |
36 id_ = epoll_create(1); | 36 id_ = epoll_create(1); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // This is the first time we register the fd, so use ADD. | 127 // This is the first time we register the fd, so use ADD. |
128 result = epoll_ctl(id_, EPOLL_CTL_ADD, fd, &event); | 128 result = epoll_ctl(id_, EPOLL_CTL_ADD, fd, &event); |
129 } | 129 } |
130 if (result == -1) return Failure::index_out_of_bounds(); | 130 if (result == -1) return Failure::index_out_of_bounds(); |
131 // Only if the call to epoll_ctl succeeded do we actually have a reference to | 131 // Only if the call to epoll_ctl succeeded do we actually have a reference to |
132 // the port. | 132 // the port. |
133 port->IncrementRef(); | 133 port->IncrementRef(); |
134 return process->program()->null_object(); | 134 return process->program()->null_object(); |
135 } | 135 } |
136 | 136 |
137 } // namespace fletch | 137 } // namespace dartino |
138 | 138 |
139 #endif // defined(FLETCH_TARGET_OS_LINUX) | 139 #endif // defined(DARTINO_TARGET_OS_LINUX) |
OLD | NEW |