OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "bin/file.h" | 5 #include "bin/file.h" |
6 | 6 |
7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
8 #include "bin/dartutils.h" | 8 #include "bin/dartutils.h" |
9 #include "bin/io_buffer.h" | 9 #include "bin/io_buffer.h" |
10 #include "bin/utils.h" | 10 #include "bin/utils.h" |
11 | 11 |
12 #include "include/dart_api.h" | 12 #include "include/dart_api.h" |
13 #include "include/dart_tools_api.h" | 13 #include "include/dart_tools_api.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 namespace bin { | 16 namespace bin { |
17 | 17 |
18 static const int kMSPerSecond = 1000; | 18 static const int kMSPerSecond = 1000; |
19 | 19 |
20 // Are we capturing output from either stdout or stderr for the VM Service? | |
21 bool capture_stdio = false; | |
22 | |
23 // Are we capturing output from stdout for the VM service? | 20 // Are we capturing output from stdout for the VM service? |
24 bool capture_stdout = false; | 21 bool File::capture_stdout_ = false; |
25 | 22 |
26 // Are we capturing output from stderr for the VM service? | 23 // Are we capturing output from stderr for the VM service? |
27 bool capture_stderr = false; | 24 bool File::capture_stderr_ = false; |
| 25 |
| 26 // Are we capturing output from either stdout or stderr for the VM Service? |
| 27 bool File::capture_any_ = false; |
28 | 28 |
29 | 29 |
30 // The file pointer has been passed into Dart as an intptr_t and it is safe | 30 // The file pointer has been passed into Dart as an intptr_t and it is safe |
31 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and | 31 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and |
32 // from there to a File pointer. | 32 // from there to a File pointer. |
33 static File* GetFilePointer(Dart_Handle handle) { | 33 static File* GetFilePointer(Dart_Handle handle) { |
34 intptr_t value = DartUtils::GetIntptrValue(handle); | 34 intptr_t value = DartUtils::GetIntptrValue(handle); |
35 return reinterpret_cast<File*>(value); | 35 return reinterpret_cast<File*>(value); |
36 } | 36 } |
37 | 37 |
(...skipping 17 matching lines...) Expand all Loading... |
55 int64_t remaining = num_bytes; | 55 int64_t remaining = num_bytes; |
56 const char* current_buffer = reinterpret_cast<const char*>(buffer); | 56 const char* current_buffer = reinterpret_cast<const char*>(buffer); |
57 while (remaining > 0) { | 57 while (remaining > 0) { |
58 int64_t bytes_written = Write(current_buffer, remaining); | 58 int64_t bytes_written = Write(current_buffer, remaining); |
59 if (bytes_written < 0) { | 59 if (bytes_written < 0) { |
60 return false; | 60 return false; |
61 } | 61 } |
62 remaining -= bytes_written; // Reduce the number of remaining bytes. | 62 remaining -= bytes_written; // Reduce the number of remaining bytes. |
63 current_buffer += bytes_written; // Move the buffer forward. | 63 current_buffer += bytes_written; // Move the buffer forward. |
64 } | 64 } |
65 if (capture_stdio) { | 65 if (capture_any_) { |
66 intptr_t fd = GetFD(); | 66 intptr_t fd = GetFD(); |
67 if (fd == STDOUT_FILENO && capture_stdout) { | 67 if (fd == STDOUT_FILENO && capture_stdout_) { |
68 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", | 68 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", |
69 reinterpret_cast<const uint8_t*>(buffer), | 69 reinterpret_cast<const uint8_t*>(buffer), |
70 num_bytes); | 70 num_bytes); |
71 } else if (fd == STDERR_FILENO && capture_stderr) { | 71 } else if (fd == STDERR_FILENO && capture_stderr_) { |
72 Dart_ServiceSendDataEvent("Stderr", "WriteEvent", | 72 Dart_ServiceSendDataEvent("Stderr", "WriteEvent", |
73 reinterpret_cast<const uint8_t*>(buffer), | 73 reinterpret_cast<const uint8_t*>(buffer), |
74 num_bytes); | 74 num_bytes); |
75 } | 75 } |
76 } | 76 } |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { | 81 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 } | 1278 } |
1279 } else { | 1279 } else { |
1280 return CObject::FileClosedError(); | 1280 return CObject::FileClosedError(); |
1281 } | 1281 } |
1282 } | 1282 } |
1283 return CObject::IllegalArgumentError(); | 1283 return CObject::IllegalArgumentError(); |
1284 } | 1284 } |
1285 | 1285 |
1286 } // namespace bin | 1286 } // namespace bin |
1287 } // namespace dart | 1287 } // namespace dart |
OLD | NEW |