OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #if defined(TARGET_OS_FUCHSIA) | 8 #if defined(TARGET_OS_FUCHSIA) |
9 | 9 |
10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
11 #include "bin/eventhandler_fuchsia.h" | 11 #include "bin/eventhandler_fuchsia.h" |
12 | 12 |
| 13 #include <magenta/status.h> |
13 #include <magenta/syscalls.h> | 14 #include <magenta/syscalls.h> |
14 #include <runtime/status.h> | |
15 | 15 |
16 #include "bin/thread.h" | 16 #include "bin/thread.h" |
17 #include "bin/utils.h" | 17 #include "bin/utils.h" |
18 | 18 |
19 namespace dart { | 19 namespace dart { |
20 namespace bin { | 20 namespace bin { |
21 | 21 |
22 EventHandlerImplementation::EventHandlerImplementation() { | 22 EventHandlerImplementation::EventHandlerImplementation() { |
23 mx_status_t status = mx_msgpipe_create(interrupt_handles_, 0); | 23 mx_status_t status = mx_msgpipe_create(interrupt_handles_, 0); |
24 if (status != NO_ERROR) { | 24 if (status != NO_ERROR) { |
25 FATAL1("mx_msgpipe_create failed: %s\n", mx_strstatus(status)); | 25 FATAL1("mx_msgpipe_create failed: %s\n", mx_status_get_string(status)); |
26 } | 26 } |
27 shutdown_ = false; | 27 shutdown_ = false; |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 EventHandlerImplementation::~EventHandlerImplementation() { | 31 EventHandlerImplementation::~EventHandlerImplementation() { |
32 mx_status_t status = mx_handle_close(interrupt_handles_[0]); | 32 mx_status_t status = mx_handle_close(interrupt_handles_[0]); |
33 if (status != NO_ERROR) { | 33 if (status != NO_ERROR) { |
34 FATAL1("mx_handle_close failed: %s\n", mx_strstatus(status)); | 34 FATAL1("mx_handle_close failed: %s\n", mx_status_get_string(status)); |
35 } | 35 } |
36 status = mx_handle_close(interrupt_handles_[1]); | 36 status = mx_handle_close(interrupt_handles_[1]); |
37 if (status != NO_ERROR) { | 37 if (status != NO_ERROR) { |
38 FATAL1("mx_handle_close failed: %s\n", mx_strstatus(status)); | 38 FATAL1("mx_handle_close failed: %s\n", mx_status_get_string(status)); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 void EventHandlerImplementation::WakeupHandler(intptr_t id, | 43 void EventHandlerImplementation::WakeupHandler(intptr_t id, |
44 Dart_Port dart_port, | 44 Dart_Port dart_port, |
45 int64_t data) { | 45 int64_t data) { |
46 InterruptMessage msg; | 46 InterruptMessage msg; |
47 msg.id = id; | 47 msg.id = id; |
48 msg.dart_port = dart_port; | 48 msg.dart_port = dart_port; |
49 msg.data = data; | 49 msg.data = data; |
50 | 50 |
51 mx_status_t status = | 51 mx_status_t status = |
52 mx_msgpipe_write(interrupt_handles_[1], &msg, sizeof(msg), NULL, 0, 0); | 52 mx_msgpipe_write(interrupt_handles_[1], &msg, sizeof(msg), NULL, 0, 0); |
53 if (status != NO_ERROR) { | 53 if (status != NO_ERROR) { |
54 FATAL1("mx_msgpipe_write failed: %s\n", mx_strstatus(status)); | 54 FATAL1("mx_msgpipe_write failed: %s\n", mx_status_get_string(status)); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 void EventHandlerImplementation::HandleInterruptFd() { | 59 void EventHandlerImplementation::HandleInterruptFd() { |
60 InterruptMessage msg; | 60 InterruptMessage msg; |
61 uint32_t bytes = kInterruptMessageSize; | 61 uint32_t bytes = kInterruptMessageSize; |
62 mx_status_t status; | 62 mx_status_t status; |
63 while (true) { | 63 while (true) { |
64 status = mx_msgpipe_read( | 64 status = mx_msgpipe_read( |
65 interrupt_handles_[0], &msg, &bytes, NULL, NULL, 0); | 65 interrupt_handles_[0], &msg, &bytes, NULL, NULL, 0); |
66 if (status != NO_ERROR) { | 66 if (status != NO_ERROR) { |
67 break; | 67 break; |
68 } | 68 } |
69 ASSERT(bytes == kInterruptMessageSize); | 69 ASSERT(bytes == kInterruptMessageSize); |
70 if (msg.id == kTimerId) { | 70 if (msg.id == kTimerId) { |
71 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); | 71 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); |
72 } else if (msg.id == kShutdownId) { | 72 } else if (msg.id == kShutdownId) { |
73 shutdown_ = true; | 73 shutdown_ = true; |
74 } else { | 74 } else { |
75 UNIMPLEMENTED(); | 75 UNIMPLEMENTED(); |
76 } | 76 } |
77 } | 77 } |
78 // status == ERR_BAD_STATE when we try to read and there are no messages | 78 // status == ERR_BAD_STATE when we try to read and there are no messages |
79 // available, so it is an error if we get here and status != ERR_BAD_STATE. | 79 // available, so it is an error if we get here and status != ERR_BAD_STATE. |
80 if (status != ERR_BAD_STATE) { | 80 if (status != ERR_BAD_STATE) { |
81 FATAL1("mx_msgpipe_read failed: %s\n", mx_strstatus(status)); | 81 FATAL1("mx_msgpipe_read failed: %s\n", mx_status_get_string(status)); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 void EventHandlerImplementation::HandleEvents() { | 86 void EventHandlerImplementation::HandleEvents() { |
87 // TODO(zra): Handle events from other handles. At the moment we are only | 87 // TODO(zra): Handle events from other handles. At the moment we are only |
88 // interrupted when there is a message on interrupt_handles_[0]. | 88 // interrupted when there is a message on interrupt_handles_[0]. |
89 HandleInterruptFd(); | 89 HandleInterruptFd(); |
90 } | 90 } |
91 | 91 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 mx_time_t timeout = | 124 mx_time_t timeout = |
125 millis * kMicrosecondsPerMillisecond * kNanosecondsPerMicrosecond; | 125 millis * kMicrosecondsPerMillisecond * kNanosecondsPerMicrosecond; |
126 mx_signals_state_t signals_state; | 126 mx_signals_state_t signals_state; |
127 mx_status_t status = mx_handle_wait_one( | 127 mx_status_t status = mx_handle_wait_one( |
128 handler_impl->interrupt_handles_[0], | 128 handler_impl->interrupt_handles_[0], |
129 MX_SIGNAL_READABLE | MX_SIGNAL_PEER_CLOSED, | 129 MX_SIGNAL_READABLE | MX_SIGNAL_PEER_CLOSED, |
130 timeout, | 130 timeout, |
131 &signals_state); | 131 &signals_state); |
132 if ((status != NO_ERROR) && (status != ERR_TIMED_OUT)) { | 132 if ((status != NO_ERROR) && (status != ERR_TIMED_OUT)) { |
133 FATAL1("mx_handle_wait_one failed: %s\n", mx_strstatus(status)); | 133 FATAL1("mx_handle_wait_one failed: %s\n", mx_status_get_string(status)); |
134 } else { | 134 } else { |
135 handler_impl->HandleTimeout(); | 135 handler_impl->HandleTimeout(); |
136 if ((signals_state.satisfied & MX_SIGNAL_READABLE) != 0) { | 136 if ((signals_state.satisfied & MX_SIGNAL_READABLE) != 0) { |
137 handler_impl->HandleEvents(); | 137 handler_impl->HandleEvents(); |
138 } | 138 } |
139 if ((signals_state.satisfied & MX_SIGNAL_PEER_CLOSED) != 0) { | 139 if ((signals_state.satisfied & MX_SIGNAL_PEER_CLOSED) != 0) { |
140 FATAL("EventHandlerImplementation::Poll: Unexpected peer closed\n"); | 140 FATAL("EventHandlerImplementation::Poll: Unexpected peer closed\n"); |
141 } | 141 } |
142 } | 142 } |
143 } | 143 } |
(...skipping 20 matching lines...) Expand all Loading... |
164 int64_t data) { | 164 int64_t data) { |
165 WakeupHandler(id, dart_port, data); | 165 WakeupHandler(id, dart_port, data); |
166 } | 166 } |
167 | 167 |
168 } // namespace bin | 168 } // namespace bin |
169 } // namespace dart | 169 } // namespace dart |
170 | 170 |
171 #endif // defined(TARGET_OS_FUCHSIA) | 171 #endif // defined(TARGET_OS_FUCHSIA) |
172 | 172 |
173 #endif // !defined(DART_IO_DISABLED) | 173 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |