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

sendMessageWithResponse method

void sendMessageWithResponse (Message 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(Message 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.write(message.data, message.handles);

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