Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
channel.cc File Reference
#include "channel.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
#include <cstdlib>
#include <vector>
#include <lib/zx/channel.h>
#include <zircon/types.h>

Go to the source code of this file.

Functions

static zircon_dart_handle_tMakeHandle (zx_handle_t handle)
 
zircon_dart_handle_pair_tzircon_dart_channel_create (uint32_t options)
 
int32_t zircon_dart_channel_write (zircon_dart_handle_t *handle, zircon_dart_byte_array_t *bytes, zircon_dart_handle_list_t *handles)
 

Function Documentation

◆ MakeHandle()

static zircon_dart_handle_t * MakeHandle ( zx_handle_t  handle)
static

Definition at line 16 of file channel.cc.

16 {
18 static_cast<zircon_dart_handle_t*>(malloc(sizeof(zircon_dart_handle_t)));
19 result->handle = handle;
20 return result;
21}
GAsyncResult * result
void * malloc(size_t size)
Definition allocation.cc:19
uint32_t handle
Definition handle.h:19

◆ zircon_dart_channel_create()

zircon_dart_handle_pair_t * zircon_dart_channel_create ( uint32_t  options)

Definition at line 23 of file channel.cc.

23 {
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}
const char * options
static zircon_dart_handle_t * MakeHandle(zx_handle_t handle)
Definition channel.cc:16
zircon_dart_handle_t * left
Definition handle.h:23

◆ zircon_dart_channel_write()

int32_t zircon_dart_channel_write ( zircon_dart_handle_t handle,
zircon_dart_byte_array_t bytes,
zircon_dart_handle_list_t handles 
)

Definition at line 37 of file channel.cc.

39 {
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}