Flutter Engine
The Flutter Engine
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
5#include "channel.h"
6
7#include "flutter/fml/logging.h"
8#include "flutter/fml/macros.h"
9
10#include <cstdlib>
11#include <vector>
12
13#include <lib/zx/channel.h>
14#include <zircon/types.h>
15
16static zircon_dart_handle_t* MakeHandle(zx_handle_t handle) {
18 static_cast<zircon_dart_handle_t*>(malloc(sizeof(zircon_dart_handle_t)));
19 result->handle = handle;
20 return result;
21}
22
24 zx_handle_t out0 = 0, out1 = 0;
25 zx_status_t status = zx_channel_create(options, &out0, &out1);
26 if (status != ZX_OK) {
27 return nullptr;
28 } else {
31 result->left = MakeHandle(out0);
32 result->right = MakeHandle(out1);
33 return result;
34 }
35}
36
40 if (!handle || (handle->handle == ZX_HANDLE_INVALID)) {
41 return ZX_ERR_BAD_HANDLE;
42 }
43
44 std::vector<zx_handle_t> zx_handles;
45 std::vector<zircon_dart_handle_t*> handle_data =
46 *reinterpret_cast<std::vector<zircon_dart_handle_t*>*>(handles->data);
47 for (auto handle_ptr : handle_data) {
48 zx_handles.push_back(handle_ptr->handle);
49 }
50
51 zx_status_t status =
52 zx_channel_write(handle->handle, 0, bytes->data, bytes->length,
53 zx_handles.data(), zx_handles.size());
54
55 // Handles are always consumed.
56 for (auto handle_ptr : handle_data) {
57 handle_ptr->handle = ZX_HANDLE_INVALID;
58 }
59
60 return status;
61}
const char * options
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:37
static zircon_dart_handle_t * MakeHandle(zx_handle_t handle)
Definition: channel.cc:16
zircon_dart_handle_pair_t * zircon_dart_channel_create(uint32_t options)
Definition: channel.cc:23
GAsyncResult * result
void * malloc(size_t size)
Definition: allocation.cc:19
uint32_t handle
Definition: handle.h:19