From 5a34c626a4c4805038283f116b380fe8bf045a10 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 26 Mar 2006 14:22:36 +0000 Subject: [PATCH] Portability --- afeed.cc | 9 ++------- afeed.h | 2 -- afeedr.cc | 4 +--- afeedr.h | 2 -- defines.h | 3 +++ main.cc | 13 +++++++++++++ vconnect.cc | 17 +++++------------ vdr.cc | 2 +- vfeed.cc | 4 +--- vfeed.h | 2 -- 10 files changed, 26 insertions(+), 32 deletions(-) diff --git a/afeed.cc b/afeed.cc index 7035087..0d1ec3c 100644 --- a/afeed.cc +++ b/afeed.cc @@ -23,8 +23,6 @@ AFeed::AFeed(Callback* tcb) : cb(*tcb) { - delayTime.tv_sec = 0; - delayTime.tv_nsec = 100000000; audioEnabled = 1; } @@ -82,16 +80,13 @@ void AFeed::threadMethod() else { // Log::getInstance()->log("AFeed", Log::DEBUG, "No data delay"); - nanosleep(&delayTime, NULL); + MILLISLEEP(100); } } else { Demuxer::getInstance()->flushAudio(); - usleep(100000); - - // FIXME, no delay here now -// if (demux_get_audio(demuxHandle, buffer, 1000) != 1000) nanosleep(&delayTime, NULL); + MILLISLEEP(100); } } } diff --git a/afeed.h b/afeed.h index ba465c9..dfd4c61 100644 --- a/afeed.h +++ b/afeed.h @@ -48,8 +48,6 @@ class AFeed : public Thread int audioEnabled; int fd; Callback& cb; - struct timespec delayTime; - }; #endif diff --git a/afeedr.cc b/afeedr.cc index 69385e6..6abc737 100644 --- a/afeedr.cc +++ b/afeedr.cc @@ -23,8 +23,6 @@ AFeedR::AFeedR(Callback* tcb, Stream* tstream) : cb(*tcb), stream(*tstream) { - delayTime.tv_sec = 0; - delayTime.tv_nsec = 100000000; } int AFeedR::init(int tfd) @@ -66,7 +64,7 @@ void AFeedR::threadMethod() } else { - nanosleep(&delayTime, NULL); + MILLISLEEP(100); } } } diff --git a/afeedr.h b/afeedr.h index 939d919..0d9d29e 100644 --- a/afeedr.h +++ b/afeedr.h @@ -47,8 +47,6 @@ class AFeedR : public Thread int fd; Callback& cb; Stream& stream; - struct timespec delayTime; - }; #endif diff --git a/defines.h b/defines.h index 1c278f3..8ab58db 100644 --- a/defines.h +++ b/defines.h @@ -32,17 +32,20 @@ typedef unsigned long long ULLONG; ULLONG htonll(ULLONG a); ULLONG ntohll(ULLONG a); +void MILLISLEEP(ULONG a); #ifdef WIN32 #define SNPRINTF _snprintf #define VSNPRINTF _vsnprintf #define STRCASECMP stricmp #define STRCASESTR StrStrI +#define STRTOULL _strtoui64 #else #define SNPRINTF snprintf #define VSNPRINTF vsnprintf #define STRCASECMP strcasecmp #define STRCASESTR strcasestr +#define STRTOULL strtoull #endif #endif diff --git a/main.cc b/main.cc index e33bae8..5ff34bc 100644 --- a/main.cc +++ b/main.cc @@ -460,3 +460,16 @@ ULLONG htonll(ULLONG a) return b; #endif } + +void MILLISLEEP(ULONG a) +{ +#ifndef WIN32 + struct timespec delayTime; + delayTime.tv_sec = a / 1000; + delayTime.tv_nsec = (a % 1000) * 1000000; + printf("%lu %lu\n", delayTime.tv_sec, delayTime.tv_nsec); + nanosleep(&delayTime, NULL); +#else + Sleep(a); +#endif +} diff --git a/vconnect.cc b/vconnect.cc index 6b19c27..7292b71 100644 --- a/vconnect.cc +++ b/vconnect.cc @@ -64,7 +64,7 @@ void VConnect::run() void VConnect::threadMethod() { - struct timespec ts; + ULONG delay = 0; int success; irun = 1; @@ -138,29 +138,22 @@ void VConnect::threadMethod() logger->log("Command", Log::DEBUG, "Connected ok, doing login"); success = vdr->doLogin(); - if (success) - { - ts.tv_sec = 0; - ts.tv_nsec = 000000000; - } - else + if (!success) { vdr->disconnect(); setOneLiner(tr("Login failed")); - ts.tv_sec = 3; - ts.tv_nsec = 0; + delay = 3000; } } else { setOneLiner(tr("Connection failed")); - ts.tv_sec = 3; - ts.tv_nsec = 0; + delay = 3000; } draw(); viewman->updateView(this); - nanosleep(&ts, NULL); + MILLISLEEP(delay); } while(!success); diff --git a/vdr.cc b/vdr.cc index 10e6d67..689d316 100644 --- a/vdr.cc +++ b/vdr.cc @@ -810,7 +810,7 @@ ULLONG VDR::getResumePoint(char* fileName) char* resumeString = configLoad("ResumeData", fileName); if (!resumeString) return 0; - ULLONG toReturn = strtoull(resumeString, NULL, 10); + ULLONG toReturn = STRTOULL(resumeString, NULL, 10); delete[] resumeString; return toReturn; } diff --git a/vfeed.cc b/vfeed.cc index b7d6a26..aaf7285 100644 --- a/vfeed.cc +++ b/vfeed.cc @@ -23,8 +23,6 @@ VFeed::VFeed(Callback* tcb) : cb(*tcb) { - delayTime.tv_sec = 0; - delayTime.tv_nsec = 100000000; } int VFeed::init(int tfd) @@ -66,7 +64,7 @@ void VFeed::threadMethod() else { // Log::getInstance()->log("VFeed", Log::DEBUG, "No data delay"); - nanosleep(&delayTime, NULL); + MILLISLEEP(100); } } } diff --git a/vfeed.h b/vfeed.h index 51cd666..93117ce 100644 --- a/vfeed.h +++ b/vfeed.h @@ -45,8 +45,6 @@ class VFeed : public Thread void threadPostStopCleanup() {}; int fd; Callback& cb; - struct timespec delayTime; - }; #endif -- 2.39.5