From: Gunnar Beutner Date: Wed, 28 Mar 2012 12:06:02 +0000 (+0200) Subject: Improved buffering behavior. X-Git-Tag: v0.0.1~703 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=221bbe9a07267516c2ee75dd547086bcb084f00f;p=icinga2 Improved buffering behavior. --- diff --git a/base/tcpclient.cpp b/base/tcpclient.cpp index 8cd95bf6b..c353b50da 100644 --- a/base/tcpclient.cpp +++ b/base/tcpclient.cpp @@ -34,14 +34,26 @@ int TCPClient::ReadableEventHandler(EventArgs::RefType ea) char buffer[4096]; int rc; - rc = recv(GetFD(), buffer, sizeof(buffer), 0); + while (true) { + rc = recv(GetFD(), buffer, sizeof(buffer), 0); - if (rc <= 0) { - Close(); - return 0; - } +#ifdef _WIN32 + if (rc < 0 && WSAGetLastError() == WSAEWOULDBLOCK) +#else /* _WIN32 */ + if (rc < 0 && errno == EAGAIN) +#endif /* _WIN32 */ + break; - m_RecvQueue->Write(buffer, rc); + if (rc <= 0) { + Close(); + return 0; + } + + m_RecvQueue->Write(buffer, rc); + + if (m_RecvQueue->GetSize() > 1024 * 1024) + break; + } EventArgs::RefType dea = new_object(); dea->Source = shared_from_this();