Flutter Engine
The Flutter Engine
file_support.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "bin/file.h"
6
7#include "bin/builtin.h"
8#include "bin/dartutils.h"
9#include "bin/io_buffer.h"
10#include "bin/utils.h"
11
13#include "include/dart_api.h"
15
16namespace dart {
17namespace bin {
18
19// Are we capturing output from stdout for the VM service?
20static bool capture_stdout = false;
21
22// Are we capturing output from stderr for the VM service?
23static bool capture_stderr = false;
24
27}
28
31}
32
34 return capture_stdout;
35}
36
38 return capture_stderr;
39}
40
41bool File::ReadFully(void* buffer, int64_t num_bytes) {
42 int64_t remaining = num_bytes;
43 char* current_buffer = reinterpret_cast<char*>(buffer);
44 while (remaining > 0) {
45 int64_t bytes_read = Read(current_buffer, remaining);
46 if (bytes_read <= 0) {
47 return false;
48 }
49 remaining -= bytes_read; // Reduce the number of remaining bytes.
50 current_buffer += bytes_read; // Move the buffer forward.
51 }
52 return true;
53}
54
55bool File::WriteFully(const void* buffer, int64_t num_bytes) {
56 int64_t remaining = num_bytes;
57 const char* current_buffer = reinterpret_cast<const char*>(buffer);
58 while (remaining > 0) {
59 // On Windows, narrowing conversion from int64_t to DWORD will cause
60 // unexpected error.
61 // On MacOS, a single write() with more than kMaxInt32 will have
62 // "invalid argument" error.
63 // Therefore, limit the size for single write.
64 int64_t byte_to_write = remaining > kMaxInt32 ? kMaxInt32 : remaining;
65 int64_t bytes_written = Write(current_buffer, byte_to_write);
66 if (bytes_written < 0) {
67 return false;
68 }
69 remaining -= bytes_written; // Reduce the number of remaining bytes.
70 current_buffer += bytes_written; // Move the buffer forward.
71 }
73 intptr_t fd = GetFD();
74 const char* result = nullptr;
75 if ((fd == STDOUT_FILENO) && capture_stdout) {
77 "Stdout", "WriteEvent", reinterpret_cast<const uint8_t*>(buffer),
78 num_bytes);
79 } else if ((fd == STDERR_FILENO) && capture_stderr) {
81 "Stderr", "WriteEvent", reinterpret_cast<const uint8_t*>(buffer),
82 num_bytes);
83 }
84 ASSERT(result == nullptr);
85 }
86 return true;
87}
88
93 if (mode == File::kDartWrite) {
95 }
96 if (mode == File::kDartAppend) {
97 return File::kWrite;
98 }
101 }
103 return File::kWriteOnly;
104 }
105 return File::kRead;
106}
107
108} // namespace bin
109} // namespace dart
int64_t Read(void *buffer, int64_t num_bytes)
bool WriteFully(const void *buffer, int64_t num_bytes)
Definition: file_support.cc:55
DartFileOpenMode
Definition: file.h:67
@ kDartWriteOnlyAppend
Definition: file.h:72
@ kDartWrite
Definition: file.h:69
@ kDartWriteOnly
Definition: file.h:71
@ kDartAppend
Definition: file.h:70
bool ReadFully(void *buffer, int64_t num_bytes)
Definition: file_support.cc:41
intptr_t GetFD()
bool result
Definition: file.h:170
int64_t Write(const void *buffer, int64_t num_bytes)
static FileOpenMode DartModeToFileMode(DartFileOpenMode mode)
Definition: file_support.cc:89
@ kWriteOnly
Definition: file.h:59
@ kWriteTruncate
Definition: file.h:60
@ kWriteOnlyTruncate
Definition: file.h:61
#define ASSERT(E)
uint8_t value
void SetCaptureStdout(bool value)
Definition: file_support.cc:25
bool ShouldCaptureStdout()
Definition: file_support.cc:33
static bool capture_stderr
Definition: file_support.cc:23
bool ShouldCaptureStderr()
Definition: file_support.cc:37
static bool capture_stdout
Definition: file_support.cc:20
void SetCaptureStderr(bool value)
Definition: file_support.cc:29
Definition: dart_vm.cc:33
DART_EXPORT char * Dart_ServiceSendDataEvent(const char *stream_id, const char *event_kind, const uint8_t *bytes, intptr_t bytes_length)
constexpr int32_t kMaxInt32
Definition: globals.h:483
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228