Flutter Engine
The Flutter Engine
Functions
channel.h File Reference
#include "basic_types.h"
#include "handle.h"
#include "macros.h"
#include <stdint.h>

Go to the source code of this file.

Functions

ZIRCON_FFI_EXPORT zircon_dart_handle_pair_tzircon_dart_channel_create (uint32_t options)
 
ZIRCON_FFI_EXPORT 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

◆ zircon_dart_channel_create()

ZIRCON_FFI_EXPORT 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
GAsyncResult * result
void * malloc(size_t size)
Definition: allocation.cc:19

◆ zircon_dart_channel_write()

ZIRCON_FFI_EXPORT 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}
uint32_t handle
Definition: handle.h:19