flutter_flutter/content_handler/unique_fdio_ns.h
Chinmay Garde 58e84c8bf0
Re-land "Support multiple shells in a single process. (#4932)" (#4998)
* Re-land "Support multiple shells in a single process. (#4932)"

This reverts commit 723c7d01439da4261bc836075fb55651ce9e7f03.
2018-04-13 13:48:15 -07:00

35 lines
844 B
C++

// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include "fdio/namespace.h"
#include "lib/fxl/logging.h"
#include "lib/fxl/memory/unique_object.h"
namespace flutter {
struct UniqueFDIONSTraits {
static fdio_ns_t* InvalidValue() { return nullptr; }
static bool IsValid(fdio_ns_t* ns) { return ns != InvalidValue(); }
static void Free(fdio_ns_t* ns) {
auto status = fdio_ns_destroy(ns);
FXL_DCHECK(status == ZX_OK);
}
};
using UniqueFDIONS = fxl::UniqueObject<fdio_ns_t*, UniqueFDIONSTraits>;
inline UniqueFDIONS UniqueFDIONSCreate() {
fdio_ns_t* ns = nullptr;
if (fdio_ns_create(&ns) == ZX_OK) {
return UniqueFDIONS{ns};
}
return UniqueFDIONS{nullptr};
}
} // namespace flutter