1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

Userland: Add try_* IPC handlers

This enables calling auto-generated IPC methods in a way that doesn't
crash the client if the peer disconnects.
This commit is contained in:
Gunnar Beutner 2021-05-03 16:51:42 +02:00 committed by Andreas Kling
parent 34cf5cf07f
commit 8a6db55e79
4 changed files with 62 additions and 27 deletions

View file

@ -42,21 +42,23 @@ Optional<DecodedImage> Client::decode_image(const ByteBuffer& encoded_data)
}
memcpy(encoded_buffer.data<void>(), encoded_data.data(), encoded_data.size());
auto response = send_sync_but_allow_failure<Messages::ImageDecoderServer::DecodeImage>(move(encoded_buffer));
auto response_or_error = try_decode_image(move(encoded_buffer));
if (!response) {
if (response_or_error.is_error()) {
dbgln("ImageDecoder died heroically");
return {};
}
auto& response = response_or_error.value();
DecodedImage image;
image.is_animated = response->is_animated();
image.loop_count = response->loop_count();
image.frames.resize(response->bitmaps().size());
image.is_animated = response.is_animated();
image.loop_count = response.loop_count();
image.frames.resize(response.bitmaps().size());
for (size_t i = 0; i < image.frames.size(); ++i) {
auto& frame = image.frames[i];
frame.bitmap = response->bitmaps()[i].bitmap();
frame.duration = response->durations()[i];
frame.bitmap = response.bitmaps()[i].bitmap();
frame.duration = response.durations()[i];
}
return image;
}