Skip to main content

fdf_channel_read_t

Type Alias fdf_channel_read_t 

Source
pub type fdf_channel_read_t = fdf_channel_read;
Expand description

A bi-directional in-process message transport capable of sending arena-managed raw data bytes as well as handles from one side to the other.

§Thread safety

Most operations on channel objects are thread-safe, except for |fdf_channel_cancel_wait|.

§Example

// Read handler for asynchronous channel reads. void read_handler(fdf_dispatcher_t* dispatcher, fdf_channel_read_t* read, zx_status_t status);

// Sends a request to the peer of |channel| and asynchronously waits for a response. void send_request(fdf_handle_t channel, fdf_dispatcher_t* dispatcher dispatcher) { fdf_arena_t* arena; zx_status_t status = fdf_arena_create(0, ‘exam’, 0, &arena);

void* data = fdf_arena_allocate(arena, 0x1000);
// Set the data to transfer
...

// Write the request to the channel.
status = fdf_channel_write(ch0, 0, arena, data, 0x1000, NULL, 0);

// Asynchronously wait for a response.
fdf_channel_read_t* channel_read = calloc(1, sizeof(fdf_channel_read_t));
channel_read->handler = read_handler;
channel_read->channel = ch0;
status = fdf_channel_wait_async(dispatcher, channel_read, 0);

// We are done with the arena.
fdf_arena_drop_ref(arena);

}

void read_handler(fdf_dispatcher_t* dispatcher, fdf_channel_read_t* read, zx_status_t status) { fdf_arena_t* arena; void* data data; uint32_t data_size; zx_handle_t* handles; uint32_t num_handles; zx_status_t status = fdf_channel_read(read->channel, 0, &arena, &data, &data_size, &handles, &num_handles); // Process the read data. …

// Read provides you with an arena which you may reuse for other requests.
// You are in charge of destroying the reference.
fdf_arena_drop_ref(arena);
free(read);

}

Aliased Type§

#[repr(C)]
pub struct fdf_channel_read_t { pub state: async_state_t, pub handler: Option<unsafe extern "C" fn(*mut fdf_dispatcher, *mut fdf_channel_read, i32)>, pub channel: u32, pub options: u32, }

Fields§

§state: async_state_t§handler: Option<unsafe extern "C" fn(*mut fdf_dispatcher, *mut fdf_channel_read, i32)>§channel: u32§options: u32