diff --git a/src/C4Chrono.h b/src/C4Chrono.h index 8757f129..9014b863 100644 --- a/src/C4Chrono.h +++ b/src/C4Chrono.h @@ -23,8 +23,6 @@ #ifndef _WIN32 -#define INFINITE 0xFFFFFFFF - unsigned long timeGetTime(void); #endif diff --git a/src/C4NetIO.cpp b/src/C4NetIO.cpp index 41c299a9..02bf4cb1 100644 --- a/src/C4NetIO.cpp +++ b/src/C4NetIO.cpp @@ -72,9 +72,6 @@ #include #include -// constants definition -const int C4NetIO::TO_INF = -1; - // simulate packet loss (loss probability in percent) // #define C4NETIO_SIMULATE_PACKETLOSS 10 @@ -575,7 +572,7 @@ bool C4NetIOTCP::Execute(int iMaxTime) // (mt-safe) #ifdef _WIN32 // wait for something to happen - if (WaitForSingleObject(Event, iMaxTime == C4NetIO::TO_INF ? INFINITE : iMaxTime) == WAIT_TIMEOUT) + if (WaitForSingleObject(Event, iMaxTime) == WAIT_TIMEOUT) // timeout -> nothing happened return true; WSAResetEvent(Event); @@ -1013,11 +1010,6 @@ void C4NetIOTCP::GetFDs(std::vector &fds) #endif -int C4NetIOTCP::GetTimeout() // (mt-safe) -{ - return TO_INF; -} - bool C4NetIOTCP::GetStatistic(int *pBroadcastRate) // (mt-safe) { // no broadcast @@ -1821,7 +1813,7 @@ HANDLE C4NetIOSimpleUDP::GetEvent() // (mt-safe) enum C4NetIOSimpleUDP::WaitResult C4NetIOSimpleUDP::WaitForSocket(int iTimeout) { // wait for anything to happen - DWORD ret = WaitForSingleObject(hEvent, iTimeout == TO_INF ? INFINITE : iTimeout); + DWORD ret = WaitForSingleObject(hEvent, iTimeout); if (ret == WAIT_TIMEOUT) return WR_Timeout; if (ret == WAIT_FAILED) @@ -1888,11 +1880,6 @@ enum C4NetIOSimpleUDP::WaitResult C4NetIOSimpleUDP::WaitForSocket(int iTimeout) #endif -int C4NetIOSimpleUDP::GetTimeout() -{ - return C4NetIO::TO_INF; -} - bool C4NetIOSimpleUDP::SetMCLoopback(int fLoopback) { // enable/disable MC loopback @@ -2303,7 +2290,7 @@ bool C4NetIOUDP::Execute(int iMaxTime) // (mt-safe) // adjust maximum block time int iMaxBlock = GetTimeout(); - if (iMaxTime == TO_INF || iMaxTime > iMaxBlock) iMaxTime = iMaxBlock; + if (iMaxTime == StdSync::Infinite || iMaxTime > iMaxBlock) iMaxTime = iMaxBlock; // execute subclass if (!C4NetIOSimpleUDP::Execute(iMaxBlock)) @@ -3160,7 +3147,7 @@ bool C4NetIOUDP::Peer::SendDirect(C4NetIOPacket &&rPacket) // (mt-safe) void C4NetIOUDP::Peer::OnConn() { // reset timeout - SetTimeout(TO_INF); + SetTimeout(StdSync::Infinite); // set status eStatus = CS_Works; // do callback @@ -3229,7 +3216,7 @@ void C4NetIOUDP::Peer::CheckCompleteIPackets() void C4NetIOUDP::Peer::SetTimeout(int iLength, int iRetryCnt) // (mt-safe) { - if (iLength != TO_INF) + if (iLength != StdSync::Infinite) iTimeout = timeGetTime() + iLength; else iTimeout = 0; @@ -3254,7 +3241,7 @@ void C4NetIOUDP::Peer::OnTimeout() Close("connection timeout"); } // reset timeout - SetTimeout(TO_INF); + SetTimeout(StdSync::Infinite); } // * C4NetIOUDP: implementation diff --git a/src/C4NetIO.h b/src/C4NetIO.h index b413f805..6e462f71 100644 --- a/src/C4NetIO.h +++ b/src/C4NetIO.h @@ -42,9 +42,6 @@ class C4NetIO : public StdSchedulerProc C4NetIO(); virtual ~C4NetIO(); - // *** constants / types - static const int TO_INF; // = -1; - using addr_t = C4Network2EndpointAddress; static std::vector GetLocalAddresses(bool unsorted = false); @@ -190,7 +187,7 @@ class C4NetIOTCP : public C4NetIO, protected CStdCSecExCallback virtual bool Close() override; virtual bool CloseBroadcast(); - virtual bool Execute(int iMaxTime = TO_INF) override; + virtual bool Execute(int iMaxTime = StdSync::Infinite) override; // * multithreading safe std::unique_ptr Bind(const addr_t &addr); @@ -208,7 +205,6 @@ class C4NetIOTCP : public C4NetIO, protected CStdCSecExCallback #else virtual void GetFDs(std::vector &fds) override; #endif - virtual int GetTimeout() override; // statistics virtual bool GetStatistic(int *pBroadcastRate) override; @@ -360,7 +356,7 @@ class C4NetIOSimpleUDP : public C4NetIO virtual bool Close() override; virtual bool CloseBroadcast(); - virtual bool Execute(int iMaxTime = TO_INF) override; + virtual bool Execute(int iMaxTime = StdSync::Infinite) override; virtual bool Send(const C4NetIOPacket &rPacket) override; virtual bool Broadcast(const C4NetIOPacket &rPacket) override; @@ -371,7 +367,6 @@ class C4NetIOSimpleUDP : public C4NetIO #else virtual void GetFDs(std::vector &fds) override; #endif - virtual int GetTimeout() override; // not implemented virtual bool Connect(const addr_t &addr) override { assert(false); return false; } @@ -451,7 +446,7 @@ class C4NetIOUDP : public C4NetIOSimpleUDP, protected CStdCSecExCallback virtual bool Close() override; virtual bool CloseBroadcast() override; - virtual bool Execute(int iMaxTime = TO_INF) override; + virtual bool Execute(int iMaxTime = StdSync::Infinite) override; virtual bool Connect(const addr_t &addr) override; virtual bool Close(const addr_t &addr) override; diff --git a/src/C4Network2Reference.cpp b/src/C4Network2Reference.cpp index 02b45aa1..b441e36b 100644 --- a/src/C4Network2Reference.cpp +++ b/src/C4Network2Reference.cpp @@ -235,7 +235,7 @@ class C4Network2HTTPClient::Impl virtual void SetNotify(C4InteractiveThread *thread) = 0; virtual bool Execute(int maxTime) = 0; - virtual int GetTimeout() = 0; + virtual int GetTimeout() { return StdSync::Infinite; } #ifdef _WIN32 virtual HANDLE GetEvent() = 0; @@ -274,8 +274,7 @@ class C4Network2HTTPClientImplCurl : public C4Network2HTTPClient::Impl bool SetServer(std::string_view serverAddress, std::uint16_t defaultPort) override; void SetNotify(class C4InteractiveThread *thread) override { this->thread.store(thread, std::memory_order_release); } - bool Execute(int iMaxTime = C4NetIO::TO_INF) override { return true; } - int GetTimeout() override { return C4NetIO::TO_INF; } + bool Execute(int iMaxTime = StdSync::Infinite) override { return true; } #ifdef _WIN32 HANDLE GetEvent() override { return nullptr; } @@ -385,7 +384,7 @@ class C4Network2HTTPClientImplNetIO : public C4Network2HTTPClient::Impl, public void SetNotify(class C4InteractiveThread *pnNotify) override { pNotify = pnNotify; } // Overridden - bool Execute(int iMaxTime = TO_INF) override; + bool Execute(int iMaxTime = StdSync::Infinite) override; int GetTimeout() override; #ifdef _WIN32 diff --git a/src/C4Network2Reference.h b/src/C4Network2Reference.h index 49eab32e..34b2431d 100644 --- a/src/C4Network2Reference.h +++ b/src/C4Network2Reference.h @@ -151,7 +151,7 @@ class C4Network2HTTPClient : public StdSchedulerProc bool SetServer(std::string_view serverAddress, std::uint16_t defaultPort = 0); void SetNotify(class C4InteractiveThread *thread); - bool Execute(int iMaxTime = C4NetIO::TO_INF) override; + bool Execute(int iMaxTime = StdSync::Infinite) override; int GetTimeout() override; #ifdef _WIN32 diff --git a/src/StdApp.h b/src/StdApp.h index 0dd5c995..3f4a058f 100644 --- a/src/StdApp.h +++ b/src/StdApp.h @@ -19,10 +19,10 @@ #include "C4Log.h" #include "C4Windows.h" +#include "StdSync.h" #include "StdWindow.h" #ifdef _WIN32 -#include "StdSync.h" const int SEC1_TIMER = 1, SEC1_MSEC = 1000; #elif defined(USE_X11) @@ -263,7 +263,7 @@ class CStdApp virtual int32_t &ScreenWidth() = 0; virtual int32_t &ScreenHeight() = 0; virtual float GetScale() = 0; - C4AppHandleResult HandleMessage(unsigned int iTimeout = INFINITE, bool fCheckTimer = true); + C4AppHandleResult HandleMessage(unsigned int iTimeout = StdSync::Infinite, bool fCheckTimer = true); void SetDisplayMode(DisplayMode mode) { pWindow->SetDisplayMode(mode); } void ResetTimer(unsigned int uDelay); CStdWindow *pWindow; diff --git a/src/StdScheduler.cpp b/src/StdScheduler.cpp index a598a904..14c221a1 100644 --- a/src/StdScheduler.cpp +++ b/src/StdScheduler.cpp @@ -73,7 +73,7 @@ bool StdScheduler::Execute(int iTimeout) { if (const int procTimeout{proc->GetTimeout()}; procTimeout >= 0) { - if (iTimeout == -1 || iTimeout > procTimeout) + if (iTimeout == StdSync::Infinite || iTimeout > procTimeout) { iTimeout = procTimeout; }