OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "nacl_io/devfs/tty_node.h" | 5 #include "nacl_io/devfs/tty_node.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 Error TtyNode::Write(const HandleAttr& attr, | 84 Error TtyNode::Write(const HandleAttr& attr, |
85 const void* buf, | 85 const void* buf, |
86 size_t count, | 86 size_t count, |
87 int* out_bytes) { | 87 int* out_bytes) { |
88 AUTO_LOCK(output_lock_); | 88 AUTO_LOCK(output_lock_); |
89 *out_bytes = 0; | 89 *out_bytes = 0; |
90 | 90 |
91 // No handler registered. | 91 // No handler registered. |
92 if (output_handler_.handler == NULL) | 92 if (output_handler_.handler == NULL) { |
| 93 // No error here; many of the tests trigger this message. |
| 94 LOG_TRACE("No output handler registered."); |
93 return EIO; | 95 return EIO; |
| 96 } |
94 | 97 |
95 int rtn = output_handler_.handler( | 98 int rtn = output_handler_.handler( |
96 static_cast<const char*>(buf), count, output_handler_.user_data); | 99 static_cast<const char*>(buf), count, output_handler_.user_data); |
97 | 100 |
98 // Negative return value means an error occured and the return | 101 // Negative return value means an error occured and the return |
99 // value is a negated errno value. | 102 // value is a negated errno value. |
100 if (rtn < 0) | 103 if (rtn < 0) |
101 return -rtn; | 104 return -rtn; |
102 | 105 |
103 *out_bytes = rtn; | 106 *out_bytes = rtn; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // TOOD(sbc): Do something more useful in response to a | 166 // TOOD(sbc): Do something more useful in response to a |
164 // failure to echo. | 167 // failure to echo. |
165 return error; | 168 return error; |
166 } | 169 } |
167 | 170 |
168 return 0; | 171 return 0; |
169 } | 172 } |
170 | 173 |
171 Error TtyNode::ProcessInput(PP_Var message) { | 174 Error TtyNode::ProcessInput(PP_Var message) { |
172 if (message.type != PP_VARTYPE_STRING) { | 175 if (message.type != PP_VARTYPE_STRING) { |
173 LOG_ERROR("ProcessInput: expected VarString but got %d.", message.type); | 176 LOG_ERROR("Expected VarString but got %d.", message.type); |
174 return EINVAL; | 177 return EINVAL; |
175 } | 178 } |
176 | 179 |
177 PepperInterface* ppapi = filesystem_->ppapi(); | 180 PepperInterface* ppapi = filesystem_->ppapi(); |
178 if (!ppapi) { | 181 if (!ppapi) { |
179 LOG_ERROR("ProcessInput: ppapi is NULL."); | 182 LOG_ERROR("ppapi is NULL."); |
180 return EINVAL; | 183 return EINVAL; |
181 } | 184 } |
182 | 185 |
183 VarInterface* var_iface = ppapi->GetVarInterface(); | 186 VarInterface* var_iface = ppapi->GetVarInterface(); |
184 if (!var_iface) { | 187 if (!var_iface) { |
185 LOG_ERROR("ProcessInput: Var interface pointer is NULL."); | 188 LOG_ERROR("Got NULL interface: Var"); |
186 return EINVAL; | 189 return EINVAL; |
187 } | 190 } |
188 | 191 |
189 uint32_t num_bytes; | 192 uint32_t num_bytes; |
190 const char* buffer = var_iface->VarToUtf8(message, &num_bytes); | 193 const char* buffer = var_iface->VarToUtf8(message, &num_bytes); |
191 Error error = ProcessInput(buffer, num_bytes); | 194 Error error = ProcessInput(buffer, num_bytes); |
192 return error; | 195 return error; |
193 } | 196 } |
194 | 197 |
195 Error TtyNode::ProcessInput(const char* buffer, size_t num_bytes) { | 198 Error TtyNode::ProcessInput(const char* buffer, size_t num_bytes) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 261 |
259 Error TtyNode::VIoctl(int request, va_list args) { | 262 Error TtyNode::VIoctl(int request, va_list args) { |
260 switch (request) { | 263 switch (request) { |
261 case TIOCNACLOUTPUT: { | 264 case TIOCNACLOUTPUT: { |
262 struct tioc_nacl_output* arg = va_arg(args, struct tioc_nacl_output*); | 265 struct tioc_nacl_output* arg = va_arg(args, struct tioc_nacl_output*); |
263 AUTO_LOCK(output_lock_); | 266 AUTO_LOCK(output_lock_); |
264 if (arg == NULL) { | 267 if (arg == NULL) { |
265 output_handler_.handler = NULL; | 268 output_handler_.handler = NULL; |
266 return 0; | 269 return 0; |
267 } | 270 } |
268 if (output_handler_.handler != NULL) | 271 if (output_handler_.handler != NULL) { |
| 272 LOG_ERROR("Output handler already set."); |
269 return EALREADY; | 273 return EALREADY; |
| 274 } |
270 output_handler_ = *arg; | 275 output_handler_ = *arg; |
271 return 0; | 276 return 0; |
272 } | 277 } |
273 case NACL_IOC_HANDLEMESSAGE: { | 278 case NACL_IOC_HANDLEMESSAGE: { |
274 struct PP_Var* message = va_arg(args, struct PP_Var*); | 279 struct PP_Var* message = va_arg(args, struct PP_Var*); |
275 return ProcessInput(*message); | 280 return ProcessInput(*message); |
276 } | 281 } |
277 case TIOCSWINSZ: { | 282 case TIOCSWINSZ: { |
278 struct winsize* size = va_arg(args, struct winsize*); | 283 struct winsize* size = va_arg(args, struct winsize*); |
279 { | 284 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 319 } |
315 | 320 |
316 Error TtyNode::Tcsetattr(int optional_actions, | 321 Error TtyNode::Tcsetattr(int optional_actions, |
317 const struct termios* termios_p) { | 322 const struct termios* termios_p) { |
318 AUTO_LOCK(node_lock_); | 323 AUTO_LOCK(node_lock_); |
319 termios_ = *termios_p; | 324 termios_ = *termios_p; |
320 return 0; | 325 return 0; |
321 } | 326 } |
322 | 327 |
323 } // namespace nacl_io | 328 } // namespace nacl_io |
OLD | NEW |