Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
channel.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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
6
7#include <lib/zx/channel.h>
8#include <zircon/types.h>
9
10#include <cstdlib>
11#include <vector>
12
14
15static zircon_dart_handle_t* MakeHandle(zx_handle_t handle) {
16 zircon_dart_handle_t* result =
17 static_cast<zircon_dart_handle_t*>(malloc(sizeof(zircon_dart_handle_t)));
18 result->handle = handle;
19 return result;
20}
21
23 zx_handle_t out0 = 0, out1 = 0;
24 zx_status_t status = zx_channel_create(options, &out0, &out1);
25 if (status != ZX_OK) {
26 return nullptr;
27 } else {
29 malloc(sizeof(zircon_dart_handle_pair_t)));
30 result->left = MakeHandle(out0);
31 result->right = MakeHandle(out1);
32 return result;
33 }
34}
35
39 if (!handle || (handle->handle == ZX_HANDLE_INVALID)) {
40 return ZX_ERR_BAD_HANDLE;
41 }
42
43 std::vector<zx_handle_t> zx_handles;
44 std::vector<zircon_dart_handle_t*> handle_data =
45 *reinterpret_cast<std::vector<zircon_dart_handle_t*>*>(handles->data);
46 for (auto handle_ptr : handle_data) {
47 zx_handles.push_back(handle_ptr->handle);
48 }
49
50 zx_status_t status =
51 zx_channel_write(handle->handle, 0, bytes->data, bytes->length,
52 zx_handles.data(), zx_handles.size());
53
54 // Handles are always consumed.
55 for (auto handle_ptr : handle_data) {
56 handle_ptr->handle = ZX_HANDLE_INVALID;
57 }
58
59 return status;
60}
int32_t zircon_dart_channel_write(zircon_dart_handle_t *handle, zircon_dart_byte_array_t *bytes, zircon_dart_handle_list_t *handles)
Definition channel.cc:36
static zircon_dart_handle_t * MakeHandle(zx_handle_t handle)
Definition channel.cc:15
zircon_dart_handle_pair_t * zircon_dart_channel_create(uint32_t options)
Definition channel.cc:22
zircon_dart_handle_t * right
Definition handle.h:24
zircon_dart_handle_t * left
Definition handle.h:23
uint32_t handle
Definition handle.h:19