컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
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 및 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();
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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."]]],[]]