From 4a25f3be727e4285a3888cfe75f43e6f58a4ed51 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 30 Apr 2018 10:25:44 -0700 Subject: [PATCH] modules/federation/backfill: Chunk direct to socket. --- modules/federation/backfill.cc | 55 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/modules/federation/backfill.cc b/modules/federation/backfill.cc index dc3f5d897..1b3b7dadb 100644 --- a/modules/federation/backfill.cc +++ b/modules/federation/backfill.cc @@ -85,40 +85,39 @@ get__backfill(client &client, room_id, event_id }; - //TODO: chunk direct to socket const unique_buffer buf { - 64_KiB * limit //TODO: XXX + 96_KiB }; - json::stack out{buf}; + resource::response::chunked response { - json::stack::object top{out}; - json::stack::member pdus_m - { - top, "pdus" - }; - - json::stack::array pdus - { - pdus_m - }; - - size_t count{0}; - for(; it && count < limit; ++count, --it) - { - const m::event &event{*it}; - pdus.append(event); - } - } - - return resource::response - { - client, json::object - { - out.completed() - } + client, http::OK }; + + json::stack out{buf, [&response] + (const const_buffer &buf) + { + response.write(buf); + return buf; + }}; + + json::stack::object top{out}; + json::stack::member pdus_m + { + top, "pdus" + }; + + json::stack::array pdus + { + pdus_m + }; + + size_t count{0}; + for(; it && count < limit; ++count, --it) + pdus.append(*it); + + return {}; } resource::method