zeroconf/AvahiPoll: migrate from TimeoutMonitor to TimerEvent
This commit is contained in:
parent
fd520eeed2
commit
11f36c0bd6
@ -20,7 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "AvahiPoll.hxx"
|
#include "AvahiPoll.hxx"
|
||||||
#include "event/SocketMonitor.hxx"
|
#include "event/SocketMonitor.hxx"
|
||||||
#include "event/TimeoutMonitor.hxx"
|
#include "event/TimerEvent.hxx"
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
FromAvahiWatchEvent(AvahiWatchEvent e)
|
FromAvahiWatchEvent(AvahiWatchEvent e)
|
||||||
@ -84,8 +84,9 @@ TimevalToChrono(const timeval &tv)
|
|||||||
return std::chrono::seconds(tv.tv_sec) + std::chrono::microseconds(tv.tv_usec);
|
return std::chrono::seconds(tv.tv_sec) + std::chrono::microseconds(tv.tv_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AvahiTimeout final : private TimeoutMonitor {
|
struct AvahiTimeout final {
|
||||||
private:
|
TimerEvent timer;
|
||||||
|
|
||||||
const AvahiTimeoutCallback callback;
|
const AvahiTimeoutCallback callback;
|
||||||
void *const userdata;
|
void *const userdata;
|
||||||
|
|
||||||
@ -93,25 +94,25 @@ public:
|
|||||||
AvahiTimeout(const struct timeval *tv,
|
AvahiTimeout(const struct timeval *tv,
|
||||||
AvahiTimeoutCallback _callback, void *_userdata,
|
AvahiTimeoutCallback _callback, void *_userdata,
|
||||||
EventLoop &_loop)
|
EventLoop &_loop)
|
||||||
:TimeoutMonitor(_loop),
|
:timer(_loop, BIND_THIS_METHOD(OnTimeout)),
|
||||||
callback(_callback), userdata(_userdata) {
|
callback(_callback), userdata(_userdata) {
|
||||||
if (tv != nullptr)
|
if (tv != nullptr)
|
||||||
Schedule(TimevalToChrono(*tv));
|
timer.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(TimevalToChrono(*tv));
|
t->timer.Schedule(TimevalToChrono(*tv));
|
||||||
else
|
else
|
||||||
t->Cancel();
|
t->timer.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TimeoutFree(AvahiTimeout *t) {
|
static void TimeoutFree(AvahiTimeout *t) {
|
||||||
delete t;
|
delete t;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
virtual void OnTimeout() {
|
void OnTimeout() {
|
||||||
callback(this, userdata);
|
callback(this, userdata);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user