summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-23 22:11:44 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-23 22:11:44 +0100
commiteb85103271329d269b5854c0131889d87adceeec (patch)
tree2a739e8f954640fb5b3cd5f83406175e7108ecf0 /Userland
parent88c5126fa72b8eedcf38b4768697709b43d7876f (diff)
downloadserenity-eb85103271329d269b5854c0131889d87adceeec.zip
ProtocolServer: Send the download payload to clients as a shared buffer
The DownloadFinished message from the server now includes a buffer ID that can be mapped into the client program. To avoid prematurely destroying the buffer, the server will hang on to it until the client lets it know that they're all good. That's what the ProtocolServer::DisownSharedBuffer message is about. In the future it would be nice if the kernel had a mechanism to allow passing ownership of a shared buffer along with an IPC message somehow.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/pro.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/Userland/pro.cpp b/Userland/pro.cpp
index ccfc6955d5..215f8489c6 100644
--- a/Userland/pro.cpp
+++ b/Userland/pro.cpp
@@ -1,5 +1,6 @@
#include <LibCore/CEventLoop.h>
#include <LibProtocol/Client.h>
+#include <LibC/SharedBuffer.h>
#include <stdio.h>
int main(int argc, char** argv)
@@ -13,8 +14,14 @@ int main(int argc, char** argv)
printf("supports HTTP? %u\n", protocol_client->is_supported_protocol("http"));
printf(" supports FTP? %u\n", protocol_client->is_supported_protocol("ftp"));
- protocol_client->on_download_finish = [&](i32 download_id, bool success) {
- printf("download %d finished, success=%u\n", download_id, success);
+ protocol_client->on_download_finish = [&](i32 download_id, bool success, u32 total_size, i32 shared_buffer_id) {
+ printf("download %d finished, success=%u, shared_buffer_id=%d\n", download_id, success, shared_buffer_id);
+ if (success) {
+ ASSERT(shared_buffer_id != -1);
+ auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(shared_buffer_id);
+ auto payload_bytes = ByteBuffer::wrap(shared_buffer->data(), total_size);
+ write(STDOUT_FILENO, payload_bytes.data(), payload_bytes.size());
+ }
loop.quit(0);
};