event/Loop: use std::chrono
This commit is contained in:
parent
3413d1bf23
commit
b042095ac2
@ -258,7 +258,7 @@ glue_state_file_init()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned interval =
|
const auto interval =
|
||||||
config_get_unsigned(ConfigOption::STATE_FILE_INTERVAL,
|
config_get_unsigned(ConfigOption::STATE_FILE_INTERVAL,
|
||||||
StateFile::DEFAULT_INTERVAL);
|
StateFile::DEFAULT_INTERVAL);
|
||||||
|
|
||||||
|
@ -37,7 +37,10 @@
|
|||||||
|
|
||||||
static constexpr Domain state_file_domain("state_file");
|
static constexpr Domain state_file_domain("state_file");
|
||||||
|
|
||||||
StateFile::StateFile(AllocatedPath &&_path, unsigned _interval,
|
constexpr std::chrono::steady_clock::duration StateFile::DEFAULT_INTERVAL;
|
||||||
|
|
||||||
|
StateFile::StateFile(AllocatedPath &&_path,
|
||||||
|
std::chrono::steady_clock::duration _interval,
|
||||||
Partition &_partition, EventLoop &_loop)
|
Partition &_partition, EventLoop &_loop)
|
||||||
:TimeoutMonitor(_loop),
|
:TimeoutMonitor(_loop),
|
||||||
path(std::move(_path)), path_utf8(path.ToUTF8()),
|
path(std::move(_path)), path_utf8(path.ToUTF8()),
|
||||||
@ -135,7 +138,7 @@ void
|
|||||||
StateFile::CheckModified()
|
StateFile::CheckModified()
|
||||||
{
|
{
|
||||||
if (!IsActive() && IsModified())
|
if (!IsActive() && IsModified())
|
||||||
ScheduleSeconds(interval);
|
Schedule(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
struct Partition;
|
struct Partition;
|
||||||
class OutputStream;
|
class OutputStream;
|
||||||
@ -34,7 +35,7 @@ class StateFile final : private TimeoutMonitor {
|
|||||||
const AllocatedPath path;
|
const AllocatedPath path;
|
||||||
const std::string path_utf8;
|
const std::string path_utf8;
|
||||||
|
|
||||||
const unsigned interval;
|
const std::chrono::steady_clock::duration interval;
|
||||||
|
|
||||||
Partition &partition;
|
Partition &partition;
|
||||||
|
|
||||||
@ -46,9 +47,9 @@ class StateFile final : private TimeoutMonitor {
|
|||||||
prev_playlist_version = 0;
|
prev_playlist_version = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr unsigned DEFAULT_INTERVAL = 2 * 60;
|
static constexpr std::chrono::steady_clock::duration DEFAULT_INTERVAL = std::chrono::minutes(2);
|
||||||
|
|
||||||
StateFile(AllocatedPath &&path, unsigned interval,
|
StateFile(AllocatedPath &&path, std::chrono::steady_clock::duration interval,
|
||||||
Partition &partition, EventLoop &loop);
|
Partition &partition, EventLoop &loop);
|
||||||
|
|
||||||
void Read();
|
void Read();
|
||||||
|
@ -28,7 +28,7 @@ Client::SetExpired()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
FullyBufferedSocket::Close();
|
FullyBufferedSocket::Close();
|
||||||
TimeoutMonitor::Schedule(0);
|
TimeoutMonitor::Schedule(std::chrono::steady_clock::duration::zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -25,14 +25,16 @@
|
|||||||
#define CLIENT_MAX_COMMAND_LIST_DEFAULT (2048*1024)
|
#define CLIENT_MAX_COMMAND_LIST_DEFAULT (2048*1024)
|
||||||
#define CLIENT_MAX_OUTPUT_BUFFER_SIZE_DEFAULT (8192*1024)
|
#define CLIENT_MAX_OUTPUT_BUFFER_SIZE_DEFAULT (8192*1024)
|
||||||
|
|
||||||
int client_timeout;
|
std::chrono::steady_clock::duration client_timeout;
|
||||||
size_t client_max_command_list_size;
|
size_t client_max_command_list_size;
|
||||||
size_t client_max_output_buffer_size;
|
size_t client_max_output_buffer_size;
|
||||||
|
|
||||||
void client_manager_init(void)
|
void client_manager_init(void)
|
||||||
{
|
{
|
||||||
client_timeout = config_get_positive(ConfigOption::CONN_TIMEOUT,
|
unsigned client_timeout_s = config_get_positive(ConfigOption::CONN_TIMEOUT,
|
||||||
CLIENT_TIMEOUT_DEFAULT);
|
CLIENT_TIMEOUT_DEFAULT);
|
||||||
|
client_timeout = std::chrono::seconds(client_timeout_s);
|
||||||
|
|
||||||
client_max_command_list_size =
|
client_max_command_list_size =
|
||||||
config_get_positive(ConfigOption::MAX_COMMAND_LIST_SIZE,
|
config_get_positive(ConfigOption::MAX_COMMAND_LIST_SIZE,
|
||||||
CLIENT_MAX_COMMAND_LIST_DEFAULT / 1024)
|
CLIENT_MAX_COMMAND_LIST_DEFAULT / 1024)
|
||||||
|
@ -42,7 +42,7 @@ Client::IdleNotify()
|
|||||||
|
|
||||||
client_puts(*this, "OK\n");
|
client_puts(*this, "OK\n");
|
||||||
|
|
||||||
TimeoutMonitor::ScheduleSeconds(client_timeout);
|
TimeoutMonitor::Schedule(client_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -24,12 +24,14 @@
|
|||||||
#include "Client.hxx"
|
#include "Client.hxx"
|
||||||
#include "command/CommandResult.hxx"
|
#include "command/CommandResult.hxx"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
static constexpr unsigned CLIENT_MAX_SUBSCRIPTIONS = 16;
|
static constexpr unsigned CLIENT_MAX_SUBSCRIPTIONS = 16;
|
||||||
static constexpr unsigned CLIENT_MAX_MESSAGES = 64;
|
static constexpr unsigned CLIENT_MAX_MESSAGES = 64;
|
||||||
|
|
||||||
extern const class Domain client_domain;
|
extern const class Domain client_domain;
|
||||||
|
|
||||||
extern int client_timeout;
|
extern std::chrono::steady_clock::duration client_timeout;
|
||||||
extern size_t client_max_command_list_size;
|
extern size_t client_max_command_list_size;
|
||||||
extern size_t client_max_output_buffer_size;
|
extern size_t client_max_output_buffer_size;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ Client::Client(EventLoop &_loop, Partition &_partition,
|
|||||||
idle_waiting(false), idle_flags(0),
|
idle_waiting(false), idle_flags(0),
|
||||||
num_subscriptions(0)
|
num_subscriptions(0)
|
||||||
{
|
{
|
||||||
TimeoutMonitor::ScheduleSeconds(client_timeout);
|
TimeoutMonitor::Schedule(client_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -34,7 +34,7 @@ Client::OnSocketInput(void *data, size_t length)
|
|||||||
if (newline == nullptr)
|
if (newline == nullptr)
|
||||||
return InputResult::MORE;
|
return InputResult::MORE;
|
||||||
|
|
||||||
TimeoutMonitor::ScheduleSeconds(client_timeout);
|
TimeoutMonitor::Schedule(client_timeout);
|
||||||
|
|
||||||
BufferedSocket::ConsumeInput(newline + 1 - p);
|
BufferedSocket::ConsumeInput(newline + 1 - p);
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
* update_enqueue(). This increases the probability that updates can
|
* update_enqueue(). This increases the probability that updates can
|
||||||
* be bundled.
|
* be bundled.
|
||||||
*/
|
*/
|
||||||
static constexpr unsigned INOTIFY_UPDATE_DELAY_S = 5;
|
static constexpr std::chrono::steady_clock::duration INOTIFY_UPDATE_DELAY =
|
||||||
|
std::chrono::seconds(5);
|
||||||
|
|
||||||
void
|
void
|
||||||
InotifyQueue::OnTimeout()
|
InotifyQueue::OnTimeout()
|
||||||
@ -42,7 +43,7 @@ InotifyQueue::OnTimeout()
|
|||||||
id = update.Enqueue(uri_utf8, false);
|
id = update.Enqueue(uri_utf8, false);
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
/* retry later */
|
/* retry later */
|
||||||
ScheduleSeconds(INOTIFY_UPDATE_DELAY_S);
|
Schedule(INOTIFY_UPDATE_DELAY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ path_in(const char *path, const char *possible_parent)
|
|||||||
void
|
void
|
||||||
InotifyQueue::Enqueue(const char *uri_utf8)
|
InotifyQueue::Enqueue(const char *uri_utf8)
|
||||||
{
|
{
|
||||||
ScheduleSeconds(INOTIFY_UPDATE_DELAY_S);
|
Schedule(INOTIFY_UPDATE_DELAY);
|
||||||
|
|
||||||
for (auto i = queue.begin(), end = queue.end(); i != end;) {
|
for (auto i = queue.begin(), end = queue.end(); i != end;) {
|
||||||
const char *current_uri = i->c_str();
|
const char *current_uri = i->c_str();
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Loop.hxx"
|
#include "Loop.hxx"
|
||||||
|
|
||||||
#include "system/Clock.hxx"
|
|
||||||
#include "TimeoutMonitor.hxx"
|
#include "TimeoutMonitor.hxx"
|
||||||
#include "SocketMonitor.hxx"
|
#include "SocketMonitor.hxx"
|
||||||
#include "IdleMonitor.hxx"
|
#include "IdleMonitor.hxx"
|
||||||
@ -29,8 +27,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
EventLoop::EventLoop()
|
EventLoop::EventLoop()
|
||||||
:SocketMonitor(*this),
|
:SocketMonitor(*this)
|
||||||
now_ms(::MonotonicClockMS())
|
|
||||||
{
|
{
|
||||||
SocketMonitor::Open(wake_fd.Get());
|
SocketMonitor::Open(wake_fd.Get());
|
||||||
SocketMonitor::Schedule(SocketMonitor::READ);
|
SocketMonitor::Schedule(SocketMonitor::READ);
|
||||||
@ -93,13 +90,13 @@ EventLoop::RemoveIdle(IdleMonitor &i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EventLoop::AddTimer(TimeoutMonitor &t, unsigned ms)
|
EventLoop::AddTimer(TimeoutMonitor &t, std::chrono::steady_clock::duration d)
|
||||||
{
|
{
|
||||||
/* can't use IsInsideOrVirgin() here because libavahi-client
|
/* can't use IsInsideOrVirgin() here because libavahi-client
|
||||||
modifies the timeout during avahi_client_free() */
|
modifies the timeout during avahi_client_free() */
|
||||||
assert(IsInsideOrNull());
|
assert(IsInsideOrNull());
|
||||||
|
|
||||||
timers.insert(TimerRecord(t, now_ms + ms));
|
timers.insert(TimerRecord(t, now + d));
|
||||||
again = true;
|
again = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +113,19 @@ EventLoop::CancelTimer(TimeoutMonitor &t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the given timeout specification to a milliseconds integer,
|
||||||
|
* to be used by functions like poll() and epoll_wait(). Any negative
|
||||||
|
* value (= never times out) is translated to the magic value -1.
|
||||||
|
*/
|
||||||
|
static constexpr int
|
||||||
|
ExportTimeoutMS(std::chrono::steady_clock::duration timeout)
|
||||||
|
{
|
||||||
|
return timeout >= timeout.zero()
|
||||||
|
? int(std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count())
|
||||||
|
: -1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EventLoop::Run()
|
EventLoop::Run()
|
||||||
{
|
{
|
||||||
@ -132,21 +142,21 @@ EventLoop::Run()
|
|||||||
assert(busy);
|
assert(busy);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
now_ms = ::MonotonicClockMS();
|
now = std::chrono::steady_clock::now();
|
||||||
again = false;
|
again = false;
|
||||||
|
|
||||||
/* invoke timers */
|
/* invoke timers */
|
||||||
|
|
||||||
int timeout_ms;
|
std::chrono::steady_clock::duration timeout;
|
||||||
while (true) {
|
while (true) {
|
||||||
auto i = timers.begin();
|
auto i = timers.begin();
|
||||||
if (i == timers.end()) {
|
if (i == timers.end()) {
|
||||||
timeout_ms = -1;
|
timeout = std::chrono::steady_clock::duration(-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout_ms = i->due_ms - now_ms;
|
timeout = i->due - now;
|
||||||
if (timeout_ms > 0)
|
if (timeout > timeout.zero())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TimeoutMonitor &m = i->timer;
|
TimeoutMonitor &m = i->timer;
|
||||||
@ -185,9 +195,9 @@ EventLoop::Run()
|
|||||||
|
|
||||||
/* wait for new event */
|
/* wait for new event */
|
||||||
|
|
||||||
poll_group.ReadEvents(poll_result, timeout_ms);
|
poll_group.ReadEvents(poll_result, ExportTimeoutMS(timeout));
|
||||||
|
|
||||||
now_ms = ::MonotonicClockMS();
|
now = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
busy = true;
|
busy = true;
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "WakeFD.hxx"
|
#include "WakeFD.hxx"
|
||||||
#include "SocketMonitor.hxx"
|
#include "SocketMonitor.hxx"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
@ -54,20 +55,20 @@ class EventLoop final : SocketMonitor
|
|||||||
* Projected monotonic_clock_ms() value when this
|
* Projected monotonic_clock_ms() value when this
|
||||||
* timer is due.
|
* timer is due.
|
||||||
*/
|
*/
|
||||||
const unsigned due_ms;
|
const std::chrono::steady_clock::time_point due;
|
||||||
|
|
||||||
TimeoutMonitor &timer;
|
TimeoutMonitor &timer;
|
||||||
|
|
||||||
constexpr TimerRecord(TimeoutMonitor &_timer,
|
constexpr TimerRecord(TimeoutMonitor &_timer,
|
||||||
unsigned _due_ms)
|
std::chrono::steady_clock::time_point _due)
|
||||||
:due_ms(_due_ms), timer(_timer) {}
|
:due(_due), timer(_timer) {}
|
||||||
|
|
||||||
bool operator<(const TimerRecord &other) const {
|
bool operator<(const TimerRecord &other) const {
|
||||||
return due_ms < other.due_ms;
|
return due < other.due;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDue(unsigned _now_ms) const {
|
bool IsDue(std::chrono::steady_clock::time_point _now) const {
|
||||||
return _now_ms >= due_ms;
|
return _now >= due;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ class EventLoop final : SocketMonitor
|
|||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
std::list<DeferredMonitor *> deferred;
|
std::list<DeferredMonitor *> deferred;
|
||||||
|
|
||||||
unsigned now_ms;
|
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
|
||||||
@ -118,12 +119,12 @@ public:
|
|||||||
~EventLoop();
|
~EventLoop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A caching wrapper for MonotonicClockMS().
|
* A caching wrapper for std::chrono::steady_clock::now().
|
||||||
*/
|
*/
|
||||||
unsigned GetTimeMS() const {
|
std::chrono::steady_clock::time_point GetTime() const {
|
||||||
assert(IsInside());
|
assert(IsInside());
|
||||||
|
|
||||||
return now_ms;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,7 +158,8 @@ public:
|
|||||||
void AddIdle(IdleMonitor &i);
|
void AddIdle(IdleMonitor &i);
|
||||||
void RemoveIdle(IdleMonitor &i);
|
void RemoveIdle(IdleMonitor &i);
|
||||||
|
|
||||||
void AddTimer(TimeoutMonitor &t, unsigned ms);
|
void AddTimer(TimeoutMonitor &t,
|
||||||
|
std::chrono::steady_clock::duration d);
|
||||||
void CancelTimer(TimeoutMonitor &t);
|
void CancelTimer(TimeoutMonitor &t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,9 +73,9 @@ MultiSocketMonitor::ReplaceSocketList(pollfd *pfds, unsigned n)
|
|||||||
void
|
void
|
||||||
MultiSocketMonitor::Prepare()
|
MultiSocketMonitor::Prepare()
|
||||||
{
|
{
|
||||||
int timeout_ms = PrepareSockets();
|
const auto timeout = PrepareSockets();
|
||||||
if (timeout_ms >= 0)
|
if (timeout >= timeout.zero())
|
||||||
TimeoutMonitor::Schedule(timeout_ms);
|
TimeoutMonitor::Schedule(timeout);
|
||||||
else
|
else
|
||||||
TimeoutMonitor::Cancel();
|
TimeoutMonitor::Cancel();
|
||||||
|
|
||||||
|
@ -163,9 +163,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @return timeout [ms] or -1 for no timeout
|
* @return timeout or a negative value for no timeout
|
||||||
*/
|
*/
|
||||||
virtual int PrepareSockets() = 0;
|
virtual std::chrono::steady_clock::duration PrepareSockets() = 0;
|
||||||
virtual void DispatchSockets() = 0;
|
virtual void DispatchSockets() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -31,21 +31,12 @@ TimeoutMonitor::Cancel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
TimeoutMonitor::Schedule(std::chrono::steady_clock::duration d)
|
||||||
TimeoutMonitor::Schedule(unsigned ms)
|
|
||||||
{
|
{
|
||||||
Cancel();
|
Cancel();
|
||||||
|
|
||||||
active = true;
|
active = true;
|
||||||
loop.AddTimer(*this, ms);
|
loop.AddTimer(*this, d);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TimeoutMonitor::ScheduleSeconds(unsigned s)
|
|
||||||
{
|
|
||||||
Cancel();
|
|
||||||
|
|
||||||
Schedule(s * 1000u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,8 +58,7 @@ public:
|
|||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Schedule(unsigned ms);
|
void Schedule(std::chrono::steady_clock::duration d);
|
||||||
void ScheduleSeconds(unsigned s);
|
|
||||||
void Cancel();
|
void Cancel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -136,7 +136,7 @@ private:
|
|||||||
InvalidateSockets();
|
InvalidateSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int PrepareSockets() override;
|
virtual std::chrono::steady_clock::duration PrepareSockets() override;
|
||||||
virtual void DispatchSockets() override;
|
virtual void DispatchSockets() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,18 +165,18 @@ AlsaInputStream::Create(const char *uri, Mutex &mutex, Cond &cond)
|
|||||||
handle, frame_size);
|
handle, frame_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
std::chrono::steady_clock::duration
|
||||||
AlsaInputStream::PrepareSockets()
|
AlsaInputStream::PrepareSockets()
|
||||||
{
|
{
|
||||||
if (IsPaused()) {
|
if (IsPaused()) {
|
||||||
ClearSocketList();
|
ClearSocketList();
|
||||||
return -1;
|
return std::chrono::steady_clock::duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = snd_pcm_poll_descriptors_count(capture_handle);
|
int count = snd_pcm_poll_descriptors_count(capture_handle);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
ClearSocketList();
|
ClearSocketList();
|
||||||
return -1;
|
return std::chrono::steady_clock::duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pollfd *pfds = pfd_buffer.Get(count);
|
struct pollfd *pfds = pfd_buffer.Get(count);
|
||||||
@ -186,7 +186,7 @@ AlsaInputStream::PrepareSockets()
|
|||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
ReplaceSocketList(pfds, count);
|
ReplaceSocketList(pfds, count);
|
||||||
return -1;
|
return std::chrono::steady_clock::duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -511,7 +511,7 @@ CurlGlobal::TimerFunction(gcc_unused CURLM *_global, long timeout_ms, void *user
|
|||||||
of 10ms. */
|
of 10ms. */
|
||||||
timeout_ms = 10;
|
timeout_ms = 10;
|
||||||
|
|
||||||
global.Schedule(timeout_ms);
|
global.Schedule(std::chrono::milliseconds(timeout_ms));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include <poll.h> /* for POLLIN, POLLOUT */
|
#include <poll.h> /* for POLLIN, POLLOUT */
|
||||||
|
|
||||||
static constexpr unsigned NFS_MOUNT_TIMEOUT = 60;
|
static constexpr std::chrono::steady_clock::duration NFS_MOUNT_TIMEOUT =
|
||||||
|
std::chrono::minutes(1);
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
NfsConnection::CancellableCallback::Stat(nfs_context *ctx,
|
NfsConnection::CancellableCallback::Stat(nfs_context *ctx,
|
||||||
@ -541,7 +542,7 @@ NfsConnection::MountInternal()
|
|||||||
postponed_mount_error = std::exception_ptr();
|
postponed_mount_error = std::exception_ptr();
|
||||||
mount_finished = false;
|
mount_finished = false;
|
||||||
|
|
||||||
TimeoutMonitor::ScheduleSeconds(NFS_MOUNT_TIMEOUT);
|
TimeoutMonitor::Schedule(NFS_MOUNT_TIMEOUT);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
in_service = false;
|
in_service = false;
|
||||||
|
@ -55,7 +55,7 @@ private:
|
|||||||
InvalidateSockets();
|
InvalidateSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int PrepareSockets() override;
|
virtual std::chrono::steady_clock::duration PrepareSockets() override;
|
||||||
virtual void DispatchSockets() override;
|
virtual void DispatchSockets() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -93,12 +93,12 @@ public:
|
|||||||
|
|
||||||
static constexpr Domain alsa_mixer_domain("alsa_mixer");
|
static constexpr Domain alsa_mixer_domain("alsa_mixer");
|
||||||
|
|
||||||
int
|
std::chrono::steady_clock::duration
|
||||||
AlsaMixerMonitor::PrepareSockets()
|
AlsaMixerMonitor::PrepareSockets()
|
||||||
{
|
{
|
||||||
if (mixer == nullptr) {
|
if (mixer == nullptr) {
|
||||||
ClearSocketList();
|
ClearSocketList();
|
||||||
return -1;
|
return std::chrono::steady_clock::duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = snd_mixer_poll_descriptors_count(mixer);
|
int count = snd_mixer_poll_descriptors_count(mixer);
|
||||||
@ -112,7 +112,7 @@ AlsaMixerMonitor::PrepareSockets()
|
|||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
ReplaceSocketList(pfds, count);
|
ReplaceSocketList(pfds, count);
|
||||||
return -1;
|
return std::chrono::steady_clock::duration(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -102,14 +102,14 @@ public:
|
|||||||
assert(state == State::CONNECTING);
|
assert(state == State::CONNECTING);
|
||||||
|
|
||||||
SetState(State::DELAY, std::move(e));
|
SetState(State::DELAY, std::move(e));
|
||||||
TimeoutMonitor::ScheduleSeconds(60);
|
TimeoutMonitor::Schedule(std::chrono::minutes(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNfsConnectionDisconnected(std::exception_ptr e) final {
|
void OnNfsConnectionDisconnected(std::exception_ptr e) final {
|
||||||
assert(state == State::READY);
|
assert(state == State::READY);
|
||||||
|
|
||||||
SetState(State::DELAY, std::move(e));
|
SetState(State::DELAY, std::move(e));
|
||||||
TimeoutMonitor::ScheduleSeconds(5);
|
TimeoutMonitor::Schedule(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual methods from DeferredMonitor */
|
/* virtual methods from DeferredMonitor */
|
||||||
|
@ -78,10 +78,10 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr unsigned
|
static constexpr std::chrono::steady_clock::duration
|
||||||
TimevalToMS(const timeval &tv)
|
TimevalToChrono(const timeval &tv)
|
||||||
{
|
{
|
||||||
return tv.tv_sec * 1000 + (tv.tv_usec + 500) / 1000;
|
return std::chrono::seconds(tv.tv_sec) + std::chrono::microseconds(tv.tv_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AvahiTimeout final : private TimeoutMonitor {
|
struct AvahiTimeout final : private TimeoutMonitor {
|
||||||
@ -96,12 +96,12 @@ public:
|
|||||||
:TimeoutMonitor(_loop),
|
:TimeoutMonitor(_loop),
|
||||||
callback(_callback), userdata(_userdata) {
|
callback(_callback), userdata(_userdata) {
|
||||||
if (tv != nullptr)
|
if (tv != nullptr)
|
||||||
Schedule(TimevalToMS(*tv));
|
Schedule(TimevalToChrono(*tv));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) {
|
static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) {
|
||||||
if (tv != nullptr)
|
if (tv != nullptr)
|
||||||
t->Schedule(TimevalToMS(*tv));
|
t->Schedule(TimevalToChrono(*tv));
|
||||||
else
|
else
|
||||||
t->Cancel();
|
t->Cancel();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user