346 {
347 if (!channel || !channel->is_valid()) {
348 return ConstructDartObject(kReadEtcResult,
ToDart(ZX_ERR_BAD_HANDLE));
349 }
350
351 uint32_t actual_bytes = 0;
352 uint32_t actual_handles = 0;
353
354
355 zx_status_t status = zx_channel_read(channel->handle(), 0, nullptr, nullptr,
356 0, 0, &actual_bytes, &actual_handles);
357 if (status != ZX_ERR_BUFFER_TOO_SMALL) {
358
359 return ConstructDartObject(kReadEtcResult,
ToDart(status));
360 }
361
362
363 ByteDataScope bytes(actual_bytes);
365 std::vector<zx_handle_info_t> handles(actual_handles);
366
367
368 status = zx_channel_read_etc(channel->handle(), 0, bytes.data(),
369 handles.data(), bytes.size(), handles.size(),
370 &actual_bytes, &actual_handles);
371 FML_DCHECK(status != ZX_OK || bytes.size() == actual_bytes);
372
373 bytes.Release();
374
375 if (status == ZX_OK) {
377
378
379 return ConstructDartObject(kReadEtcResult,
ToDart(status),
380 bytes.dart_handle(),
ToDart(actual_bytes),
381 MakeHandleInfoList(handles));
382 } else {
383 return ConstructDartObject(kReadEtcResult,
ToDart(status));
384 }
385}