X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-qt%2Fqt-watch.cpp;h=dac9dcc7ea116d0328f219ca3be1b1bd619224b1;hb=66cfff47e34e1f4ad7090d074e5c04d648d61a13;hp=c5052fd411f875d720383701bf2e3ff4d8d09a95;hpb=4ddfb3cc4ac10efff11fc58693ae2aacf592fb73;p=catta diff --git a/avahi-qt/qt-watch.cpp b/avahi-qt/qt-watch.cpp index c5052fd..dac9dcc 100644 --- a/avahi-qt/qt-watch.cpp +++ b/avahi-qt/qt-watch.cpp @@ -27,6 +27,7 @@ #include #include #endif +#include #include "qt-watch.h" class AvahiWatch : public QObject @@ -113,6 +114,9 @@ AvahiTimeout::AvahiTimeout(const struct timeval* tv, AvahiTimeoutCallback callba m_callback(callback), m_userdata(userdata) { connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout())); +#ifdef QT4 + m_timer.setSingleShot(true); +#endif update(tv); } @@ -120,9 +124,12 @@ void AvahiTimeout::update(const struct timeval *tv) { m_timer.stop(); if (tv) { - struct timeval now; - gettimeofday(&now, 0); - m_timer.start((tv->tv_sec-now.tv_sec)*1000+(tv->tv_usec-now.tv_usec)/1000); + AvahiUsec u = avahi_age(tv)/1000; +#ifdef QT4 + m_timer.start( (u>0) ? 0 : -u); +#else + m_timer.start( (u>0) ? 0 : -u,true); +#endif } } @@ -168,19 +175,19 @@ static void q_timeout_free(AvahiTimeout *t) delete t; } -static AvahiPoll qt_poll; - const AvahiPoll* avahi_qt_poll_get(void) { - qt_poll.userdata=0; - qt_poll.watch_new = q_watch_new; - qt_poll.watch_free = q_watch_free; - qt_poll.watch_update = q_watch_update; - qt_poll.watch_get_events = q_watch_get_events; - - qt_poll.timeout_new = q_timeout_new; - qt_poll.timeout_free = q_timeout_free; - qt_poll.timeout_update = q_timeout_update; + static const AvahiPoll qt_poll = { + NULL, + q_watch_new, + q_watch_update, + q_watch_get_events, + q_watch_free, + q_timeout_new, + q_timeout_update, + q_timeout_free + }; + return &qt_poll; }