From 202706381e5072eea5877946e6986ef03eeb940b Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 7 Jun 2011 16:35:49 +0000 Subject: [PATCH] * Added TODOs where IsDataPending() is called incorrectly. Since it has stupid semantics, I'd recommend introducing an _IsDataPending() with sane semantics and use that. * IsDataPending() Added TODO regarding possible overflow. * SetTimeout(): Added TODO regarding consistency. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42009 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/network/libnetapi/NetEndpoint.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/kits/network/libnetapi/NetEndpoint.cpp b/src/kits/network/libnetapi/NetEndpoint.cpp index 0d45bd3c83..e50225d96f 100644 --- a/src/kits/network/libnetapi/NetEndpoint.cpp +++ b/src/kits/network/libnetapi/NetEndpoint.cpp @@ -295,6 +295,7 @@ void BNetEndpoint::SetTimeout(bigtime_t timeout) { fTimeout = timeout; + // TODO: Map value < 0 to B_INFINITE_TIMEOUT or use -1 by default. } @@ -416,6 +417,8 @@ BNetEndpoint::Listen(int backlog) BNetEndpoint* BNetEndpoint::Accept(int32 timeout) { + // TODO: IsDataPending() expects 0 as special value for infinite timeout, + // hence the following call is broken for timeout < 0 and timeout == 0. if (!IsDataPending(timeout < 0 ? B_INFINITE_TIMEOUT : 1000LL * timeout)) return NULL; @@ -464,6 +467,7 @@ BNetEndpoint::IsDataPending(bigtime_t timeout) if (timeout > 0) { tv.tv_sec = timeout / 1000000; + // TODO: A big value (e.g. B_INFINITE_TIMEOUT) will overflow! tv.tv_usec = (timeout % 1000000); } @@ -482,6 +486,8 @@ BNetEndpoint::Receive(void* buffer, size_t length, int flags) if (fSocket < 0 && _SetupSocket() != B_OK) return fStatus; + // TODO: For fTimeout == 0 this is broken as IsDataPending(0) means wait + // without timeout. Furthermore the default fTimeout is B_INFINITE_TIMEOUT. if (fTimeout >= 0 && IsDataPending(fTimeout) == false) return 0; @@ -510,6 +516,8 @@ BNetEndpoint::ReceiveFrom(void* buffer, size_t length, if (fSocket < 0 && _SetupSocket() != B_OK) return fStatus; + // TODO: For fTimeout == 0 this is broken as IsDataPending(0) means wait + // without timeout. Furthermore the default fTimeout is B_INFINITE_TIMEOUT. if (fTimeout >= 0 && IsDataPending(fTimeout) == false) return 0;