blob: af9bd95c6a79f5cb708ef2d3be88077275829f24 [file] [log] [blame] [view]
# sendMessageWithResponse method
void sendMessageWithResponse
([OutgoingMessage](../../package-fidl_fidl/OutgoingMessage-class.md) message, Function callback)
<p>Sends the given messages over the bound channel and registers a callback
to handle the response.</p>
<p>Used by subclasses of <a href="../../package-fidl_fidl/Proxy-class.md">Proxy&lt;T&gt;</a> to send encoded messages.</p>
## Implementation
```dart
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++;
}
```