Google is committed to advancing racial equity for Black communities. See how.

sendMessageWithResponse method

*<Null safety>*

void sendMessageWithResponse (OutgoingMessage message, Completer completer)

Sends the given messages over the bound channel and registers a Completer to handle the response.

Used by subclasses of AsyncProxy<T> to send encoded messages.

Implementation

void sendMessageWithResponse(
    OutgoingMessage message, Completer<dynamic> completer) {
  if (!_reader.isBound) {
    proxyError(FidlStateException(
        'AsyncProxyController<${$interfaceName}> is closed.'));
    return;
  }

  const int _userspaceTxidMask = 0x7FFFFFFF;

  int txid = _nextTxid++ & _userspaceTxidMask;
  while (txid == 0 || _completerMap.containsKey(txid))
    txid = _nextTxid++ & _userspaceTxidMask;
  message.txid = txid;
  _completerMap[message.txid] = completer;
  final int status =
      _reader.channel!.writeEtc(message.data, message.handleDispositions);

  if (status != ZX.OK) {
    proxyError(FidlError(
        'AsyncProxyController<${$interfaceName}> failed to write to channel: ${_reader.channel} (status: $status)'));
    return;
  }
}