mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:45:08 +00:00
ProtocolServer: Avoid blocking all downloads when client stops reading
Fixes #4668.
This commit is contained in:
parent
83fed3fd5d
commit
2568a93b5d
7 changed files with 45 additions and 28 deletions
|
@ -28,7 +28,6 @@
|
|||
#include <LibHTTP/HttpRequest.h>
|
||||
#include <ProtocolServer/HttpDownload.h>
|
||||
#include <ProtocolServer/HttpProtocol.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace ProtocolServer {
|
||||
|
||||
|
@ -52,18 +51,15 @@ OwnPtr<Download> HttpProtocol::start_download(ClientConnection& client, const St
|
|||
request.set_headers(headers);
|
||||
request.set_body(body);
|
||||
|
||||
int fd_pair[2] { 0 };
|
||||
if (pipe(fd_pair) != 0) {
|
||||
auto saved_errno = errno;
|
||||
dbgln("Protocol: pipe() failed: {}", strerror(saved_errno));
|
||||
auto pipe_result = get_pipe_for_download();
|
||||
if (pipe_result.is_error())
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto output_stream = make<OutputFileStream>(fd_pair[1]);
|
||||
auto output_stream = make<OutputFileStream>(pipe_result.value().write_fd);
|
||||
output_stream->make_unbuffered();
|
||||
auto job = HTTP::HttpJob::construct(request, *output_stream);
|
||||
auto download = HttpDownload::create_with_job({}, client, (HTTP::HttpJob&)*job, move(output_stream));
|
||||
download->set_download_fd(fd_pair[0]);
|
||||
download->set_download_fd(pipe_result.value().read_fd);
|
||||
job->start();
|
||||
return download;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue