Chromium Code Reviews| 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 | 14 |
| 14 namespace dart { | 15 namespace dart { |
| 15 namespace bin { | 16 namespace bin { |
| 16 | 17 |
| 17 static const int kMSPerSecond = 1000; | 18 static const int kMSPerSecond = 1000; |
| 18 | 19 |
| 20 // Are we capturing output from either stdout or stderr for the VM Service? | |
| 21 bool captureStdio = false; | |
|
Cutch
2015/07/13 14:10:29
capture_stdio
turnidge
2015/07/13 22:50:36
Done.
| |
| 22 | |
| 23 // Are we capturing output from stdout for the VM service? | |
| 24 bool captureStdout = false; | |
|
Cutch
2015/07/13 14:10:29
capture_stdout
...
turnidge
2015/07/13 22:50:36
Done.
| |
| 25 | |
| 26 // Are we capturing output from stderr for the VM service? | |
| 27 bool captureStderr = false; | |
| 28 | |
| 19 | 29 |
| 20 // 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 |
| 21 // 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 |
| 22 // from there to a File pointer. | 32 // from there to a File pointer. |
| 23 static File* GetFilePointer(Dart_Handle handle) { | 33 static File* GetFilePointer(Dart_Handle handle) { |
| 24 intptr_t value = DartUtils::GetIntptrValue(handle); | 34 intptr_t value = DartUtils::GetIntptrValue(handle); |
| 25 return reinterpret_cast<File*>(value); | 35 return reinterpret_cast<File*>(value); |
| 26 } | 36 } |
| 27 | 37 |
| 28 | 38 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 45 int64_t remaining = num_bytes; | 55 int64_t remaining = num_bytes; |
| 46 const char* current_buffer = reinterpret_cast<const char*>(buffer); | 56 const char* current_buffer = reinterpret_cast<const char*>(buffer); |
| 47 while (remaining > 0) { | 57 while (remaining > 0) { |
| 48 int64_t bytes_written = Write(current_buffer, remaining); | 58 int64_t bytes_written = Write(current_buffer, remaining); |
| 49 if (bytes_written < 0) { | 59 if (bytes_written < 0) { |
| 50 return false; | 60 return false; |
| 51 } | 61 } |
| 52 remaining -= bytes_written; // Reduce the number of remaining bytes. | 62 remaining -= bytes_written; // Reduce the number of remaining bytes. |
| 53 current_buffer += bytes_written; // Move the buffer forward. | 63 current_buffer += bytes_written; // Move the buffer forward. |
| 54 } | 64 } |
| 65 if (captureStdio) { | |
| 66 intptr_t fd = GetFD(); | |
| 67 if (fd == 1 && captureStdout) { | |
|
Cutch
2015/07/13 14:10:29
(fd == STDOUT_FILENO) &&
turnidge
2015/07/13 22:50:36
Done. Also fixed existing usage of 0, 1, 2 in Fil
| |
| 68 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", | |
| 69 reinterpret_cast<const uint8_t*>(buffer), | |
| 70 num_bytes); | |
| 71 } else if (fd == 2 && captureStderr) { | |
|
Cutch
2015/07/13 14:10:29
(fd == STDERR_FILENO) &&
turnidge
2015/07/13 22:50:36
Done.
| |
| 72 Dart_ServiceSendDataEvent("Stderr", "WriteEvent", | |
| 73 reinterpret_cast<const uint8_t*>(buffer), | |
| 74 num_bytes); | |
| 75 } | |
| 76 } | |
| 55 return true; | 77 return true; |
| 56 } | 78 } |
| 57 | 79 |
| 58 | 80 |
| 59 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { | 81 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { |
| 60 ASSERT(mode == File::kDartRead || | 82 ASSERT(mode == File::kDartRead || |
| 61 mode == File::kDartWrite || | 83 mode == File::kDartWrite || |
| 62 mode == File::kDartAppend || | 84 mode == File::kDartAppend || |
| 63 mode == File::kDartWriteOnly || | 85 mode == File::kDartWriteOnly || |
| 64 mode == File::kDartWriteOnlyAppend); | 86 mode == File::kDartWriteOnlyAppend); |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1256 } | 1278 } |
| 1257 } else { | 1279 } else { |
| 1258 return CObject::FileClosedError(); | 1280 return CObject::FileClosedError(); |
| 1259 } | 1281 } |
| 1260 } | 1282 } |
| 1261 return CObject::IllegalArgumentError(); | 1283 return CObject::IllegalArgumentError(); |
| 1262 } | 1284 } |
| 1263 | 1285 |
| 1264 } // namespace bin | 1286 } // namespace bin |
| 1265 } // namespace dart | 1287 } // namespace dart |
| OLD | NEW |