client/BackgroundCommand: infrastructure for commands running in background

This commit is contained in:
Max Kellermann
2019-04-03 14:31:57 +02:00
parent 28fc1d555f
commit 9f1c23e217
11 changed files with 272 additions and 0 deletions

View File

@@ -18,8 +18,10 @@
*/
#include "Client.hxx"
#include "Config.hxx"
#include "Partition.hxx"
#include "Instance.hxx"
#include "BackgroundCommand.hxx"
#include "util/Domain.hxx"
#include "config.h"
@@ -27,6 +29,37 @@ Client::~Client() noexcept
{
if (FullyBufferedSocket::IsDefined())
FullyBufferedSocket::Close();
if (background_command) {
background_command->Cancel();
background_command.reset();
}
}
void
Client::SetBackgroundCommand(std::unique_ptr<BackgroundCommand> _bc) noexcept
{
assert(!background_command);
assert(_bc);
background_command = std::move(_bc);
/* disable timeouts while in "idle" */
timeout_event.Cancel();
}
void
Client::OnBackgroundCommandFinished() noexcept
{
assert(background_command);
background_command.reset();
/* just in case OnSocketInput() has returned
InputResult::PAUSE meanwhile */
ResumeInput();
timeout_event.Schedule(client_timeout);
}
Instance &