recvMessage method
Receive a message from this socket
This wraps the native srt_recvmsg2 function to receive messages
in message mode with control information.
bufferSize is the maximum number of bytes to receive (default 1500)
Returns an SrtMessage containing the payload and metadata. Returns a message with empty payload if the receive timeout expired.
Throws SrtException if receiving fails
Implementation
SrtMessage recvMessage({int bufferSize = 1500}) {
_checkNotClosed();
final buffer = calloc<ffi.Char>(bufferSize);
final mctrl = calloc<SRT_MSGCTRL>();
try {
// Initialize message control
Srt.bindings.srt_msgctrl_init(mctrl);
final bytesReceived = Srt.bindings.srt_recvmsg2(
_socketHandle,
buffer,
bufferSize,
mctrl,
);
checkSrtResult(bytesReceived, operation: "receive menssage, no bytes received");
// Convert native buffer to Dart list
final payload = bytesReceived > 0
? Uint8List(bytesReceived)
: Uint8List(0);
for (int i = 0; i < bytesReceived; i++) {
payload[i] = buffer[i];
}
// Create message control info from native structure
final control = MessageControl.fromNative(mctrl.ref);
return SrtMessage(
payload: payload,
control: control,
bytesReceived: bytesReceived,
);
} finally {
calloc.free(buffer);
calloc.free(mctrl);
}
}