sendMessageWithResponse method

void sendMessageWithResponse (OutgoingMessage message, Function callback)

Implementation

void sendMessageWithResponse(OutgoingMessage message, Function callback) {
  if (!_reader.isBound) {
    proxyError('The sender is closed.');
    return;
  }

  const int _kUserspaceTxidMask = 0x7FFFFFFF;

  int txid = _nextTxid++ & _kUserspaceTxidMask;
  while (txid == 0 || _callbackMap.containsKey(txid))
    txid = _nextTxid++ & _kUserspaceTxidMask;
  message.txid = txid;
  final int status =
      _reader.channel!.writeEtc(message.data, message.handleDispositions);

  if (status != ZX.OK) {
    proxyError(
        'Failed to write to channel: ${_reader.channel} (status: $status)');
    return;
  }

  _callbackMap[message.txid] = callback;
  _pendingResponsesCount++;
}