1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <lib/svc/outgoing.h> 6 #include <zircon/process.h> 7 #include <zircon/processargs.h> 8 9 #include <utility> 10 11 namespace svc { 12 Outgoing(async_dispatcher_t * dispatcher)13Outgoing::Outgoing(async_dispatcher_t* dispatcher) 14 : vfs_(dispatcher), 15 root_dir_(fbl::MakeRefCounted<fs::PseudoDir>()), 16 public_dir_(fbl::MakeRefCounted<fs::PseudoDir>()) { 17 root_dir_->AddEntry("public", public_dir_); 18 } 19 20 Outgoing::~Outgoing() = default; 21 Serve(zx::channel dir_request)22zx_status_t Outgoing::Serve(zx::channel dir_request) { 23 if (!dir_request) 24 return ZX_ERR_BAD_HANDLE; 25 return vfs_.ServeDirectory(root_dir_, std::move(dir_request)); 26 } 27 ServeFromStartupInfo()28zx_status_t Outgoing::ServeFromStartupInfo() { 29 zx_handle_t dir_request = zx_take_startup_handle(PA_DIRECTORY_REQUEST); 30 return Serve(zx::channel(dir_request)); 31 } 32 33 } // namespace svc 34