send method
Send one frame to the peer.
An asynchronous transport may fail the whole session closed when accepting another frame would exceed its bounded pending-output budget.
Implementation
@override
void send(RemoteFrame frame) {
if (_closed) return;
final bytes = encodeFrame(frame);
final nextPendingBytes = _pendingSendBytes + bytes.length;
final nextPendingFrames = _pendingSendFrames + 1;
if (nextPendingBytes > _maxPendingSendBytes ||
nextPendingFrames > _maxPendingSendFrames) {
final error = StateError(
'UnixSocketFrameTransport pending output would reach '
'$nextPendingFrames frames / $nextPendingBytes bytes, exceeding hard '
'limits of $_maxPendingSendFrames frames / $_maxPendingSendBytes '
'bytes. The session was terminated instead of dropping a frame and '
'desynchronizing the peer.',
);
final stackTrace = StackTrace.current;
_abortTeardown = _tearDownPendingOutput(
error: error,
stackTrace: stackTrace,
);
return;
}
_sendQueue.add(bytes);
_pendingSendBytes = nextPendingBytes;
_pendingSendFrames = nextPendingFrames;
if (!_pumpRunning) {
_pumpRunning = true;
// Kept so a graceful [close] can await the in-flight flush. _sendPump
// never throws (it catches disconnect errors), so this future never
// rejects.
_pumpFuture = _sendPump();
}
}