From: Adam Dickmeiss Date: Tue, 13 Apr 2010 13:32:36 +0000 (+0200) Subject: Add pazpar2_sleep utility X-Git-Tag: v1.4.0~41 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=29e02dd1c6ecdbb2cb1546324d460b3e0dcd2435;p=pazpar2-moved-to-github.git Add pazpar2_sleep utility --- diff --git a/src/eventl.c b/src/eventl.c index 1d72235..4992391 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #endif +#include #include #include @@ -167,7 +168,7 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) IOCHAN p, *nextp; fd_set in, out, except; int res, max; - static struct timeval nullto = {0, 0}, to; + static struct timeval to; struct timeval *timeout; FD_ZERO(&in); @@ -310,6 +311,18 @@ void iochan_man_events(iochan_man_t man) event_loop(man, &man->channel_list); } +void pazpar2_sleep(double d) +{ +#ifdef WIN32 + Sleep( (DWORD) (d * 1000)); +#else + struct timeval tv; + tv.tv_sec = floor(d); + tv.tv_usec = (d - floor(d)) * 1000000; + select(0, 0, 0, 0, &tv); +#endif +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/eventl.h b/src/eventl.h index 1e701b8..e22b90e 100644 --- a/src/eventl.h +++ b/src/eventl.h @@ -76,6 +76,8 @@ void iochan_man_destroy(iochan_man_t *mp); IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name); +void pazpar2_sleep(double d); + #endif /* * Local variables: