จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
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();
เรียกใช้แบบไม่พร้อมกัน
คุณยังสามารถเรียกใช้แซนด์บ็อกซ์แบบไม่พร้อมกันเพื่อไม่ให้บล็อกจนกว่าจะได้ผลลัพธ์ ซึ่งจะเป็นประโยชน์ เช่น เมื่อสื่อสารกับแซนด์บ็อกซ์ ข้อมูลโค้ดด้านล่างแสดงกรณีการใช้งานนี้ ดูตัวอย่างโดยละเอียดเพิ่มเติมได้ที่ crc4 และ tool
#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();
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2023-12-06 UTC
[[["เข้าใจง่าย","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 UTC"],[[["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."]]],[]]