透過集合功能整理內容
你可以依據偏好儲存及分類內容。
4. 執行沙箱
在前幾節中,您已備妥沙箱環境、政策、執行者和沙箱。下一步是建立並執行 Sandbox2
物件。
同步執行
沙箱可以同步執行,因此在產生結果之前會進行封鎖。以下程式碼片段示範 Sandbox2
物件及其同步執行作業的例項。如需更詳細的範例,請參閱靜態一節。
#include "sandboxed_api/sandbox2/sandbox2.h"
sandbox2::Sandbox2 s2(std::move(executor), std::move(policy));
sandbox2::Result result = s2.Run(); // Synchronous
LOG(INFO) << "Result of sandbox execution: " << result.ToString();
以非同步方式執行
您也可以非同步執行沙箱,直到出現結果為止。例如,在與 Sandboxee 進行通訊時,這項功能就非常實用。以下程式碼片段示範了這個用途。如需更詳細的範例,請參閱 crc4 和工具。
#include "sandboxed_api/sandbox2/sandbox2.h"
sandbox2::Sandbox2 s2(std::move(executor), std::move(policy));
if (s2.RunAsync()) {
// Communicate with sandboxee, use s2.Kill() to kill it if needed
// ...
}
Sandbox2::Result result = s2.AwaitResult();
LOG(INFO) << "Final execution status: " << result.ToString();
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-12-06 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2023-12-06 (世界標準時間)。"],[[["Sandbox2 can be executed synchronously, blocking until a result is obtained, or asynchronously, allowing for concurrent operations and communication with the sandboxed process."],["Running synchronously involves creating a `Sandbox2` object and directly calling `Run()` to execute it and retrieve the result."],["Asynchronous execution utilizes `RunAsync()` to initiate the sandboxed process and `AwaitResult()` to obtain the final outcome, enabling communication with the sandboxee during execution."],["Example code snippets and links to more detailed examples are provided for both synchronous and asynchronous approaches to running the sandbox."]]],[]]