mirror of
https://github.com/matrix-construct/construct
synced 2024-10-01 21:28:53 +02:00
modules/media: Various cleanup / reenable assertions.
This commit is contained in:
parent
523ef5f1db
commit
05369c5d3a
2 changed files with 25 additions and 15 deletions
|
@ -37,7 +37,7 @@ get__download_local(client &client,
|
||||||
const string_view &file,
|
const string_view &file,
|
||||||
const m::room &room);
|
const m::room &room);
|
||||||
|
|
||||||
resource::response
|
static resource::response
|
||||||
get__download(client &client,
|
get__download(client &client,
|
||||||
const resource::request &request)
|
const resource::request &request)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +78,7 @@ get__download(client &client,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
resource::response
|
static resource::response
|
||||||
get__download_local(client &client,
|
get__download_local(client &client,
|
||||||
const resource::request &request,
|
const resource::request &request,
|
||||||
const string_view &server,
|
const string_view &server,
|
||||||
|
@ -127,7 +127,7 @@ get__download_local(client &client,
|
||||||
sent += write_all(*client.sock, block);
|
sent += write_all(*client.sock, block);
|
||||||
});
|
});
|
||||||
|
|
||||||
//assert(sent == file_size);
|
assert(sent == file_size);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,9 +130,13 @@ try
|
||||||
hostname
|
hostname
|
||||||
};
|
};
|
||||||
|
|
||||||
char buf[6_KiB];
|
const unique_buffer<mutable_buffer> buf
|
||||||
|
{
|
||||||
|
16_KiB
|
||||||
|
};
|
||||||
|
|
||||||
window_buffer wb{buf};
|
window_buffer wb{buf};
|
||||||
thread_local char uri[2_KiB];
|
thread_local char uri[4_KiB];
|
||||||
http::request
|
http::request
|
||||||
{
|
{
|
||||||
wb, hostname, "GET", fmt::sprintf
|
wb, hostname, "GET", fmt::sprintf
|
||||||
|
@ -149,7 +153,7 @@ try
|
||||||
// Remaining space in buffer is used for received head
|
// Remaining space in buffer is used for received head
|
||||||
const mutable_buffer in_head
|
const mutable_buffer in_head
|
||||||
{
|
{
|
||||||
buf + size(out_head), sizeof(buf) - size(out_head)
|
data(buf) + size(out_head), size(buf) - size(out_head)
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: --- This should use the progress callback to build blocks
|
//TODO: --- This should use the progress callback to build blocks
|
||||||
|
@ -202,7 +206,7 @@ try
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send it off to user first
|
// Send it off to user first
|
||||||
resource::response
|
const resource::response response
|
||||||
{
|
{
|
||||||
client, remote_request.in.content, content_type
|
client, remote_request.in.content, content_type
|
||||||
};
|
};
|
||||||
|
@ -212,7 +216,7 @@ try
|
||||||
write_file(room, remote_request.in.content, content_type)
|
write_file(room, remote_request.in.content, content_type)
|
||||||
};
|
};
|
||||||
|
|
||||||
return {};
|
return response;
|
||||||
}
|
}
|
||||||
catch(const ircd::server::unavailable &e)
|
catch(const ircd::server::unavailable &e)
|
||||||
{
|
{
|
||||||
|
@ -259,18 +263,24 @@ get__thumbnail_local(client &client,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send HTTP head to client
|
// Send HTTP head to client
|
||||||
resource::response
|
const resource::response response
|
||||||
{
|
{
|
||||||
client, http::OK, content_type, file_size
|
client, http::OK, content_type, file_size
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t sent{0}, read;
|
size_t sent{0};
|
||||||
read = read_each_block(room, [&client, &sent]
|
const auto sink{[&client, &sent]
|
||||||
(const string_view &block)
|
(const string_view &block)
|
||||||
{
|
{
|
||||||
sent += write_all(*client.sock, block);
|
sent += client.write_all(block);
|
||||||
});
|
}};
|
||||||
|
|
||||||
//assert(sent == file_size);
|
const size_t read
|
||||||
return {};
|
{
|
||||||
|
read_each_block(room, sink)
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(read == file_size);
|
||||||
|
assert(read == sent);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue