From 78f9c572119aef08c9115ad61caa41e82b41c98a Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 26 Aug 2019 09:43:23 +0100 Subject: Fix the haproxy module losing initial data in some circumstances. --- src/modules/m_haproxy.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/modules/m_haproxy.cpp b/src/modules/m_haproxy.cpp index 4d0e52514..19aac8ebd 100644 --- a/src/modules/m_haproxy.cpp +++ b/src/modules/m_haproxy.cpp @@ -219,7 +219,16 @@ class HAProxyHook : public IOHookMiddle return true; } - int ReadProxyAddress(StreamSocket* sock) + int ReadData(std::string& destrecvq) + { + // Once connected we handle no special data. + std::string& recvq = GetRecvQ(); + destrecvq.append(recvq); + recvq.clear(); + return 1; + } + + int ReadProxyAddress(StreamSocket* sock, std::string& destrecvq) { // Block until we have the entire address. std::string& recvq = GetRecvQ(); @@ -276,14 +285,15 @@ class HAProxyHook : public IOHookMiddle // Erase the processed proxy information from the receive queue. recvq.erase(0, address_length); + break; } // We're done! state = HPS_CONNECTED; - return 1; + return ReadData(destrecvq); } - int ReadProxyHeader(StreamSocket* sock) + int ReadProxyHeader(StreamSocket* sock, std::string& destrecvq) { // Block until we have a header. std::string& recvq = GetRecvQ(); @@ -359,7 +369,7 @@ class HAProxyHook : public IOHookMiddle } state = HPS_WAITING_FOR_ADDRESS; - return ReadProxyAddress(sock); + return ReadProxyAddress(sock, destrecvq); } public: @@ -384,16 +394,13 @@ class HAProxyHook : public IOHookMiddle switch (state) { case HPS_WAITING_FOR_HEADER: - return ReadProxyHeader(sock); + return ReadProxyHeader(sock, destrecvq); case HPS_WAITING_FOR_ADDRESS: - return ReadProxyAddress(sock); + return ReadProxyAddress(sock, destrecvq); case HPS_CONNECTED: - std::string& recvq = GetRecvQ(); - destrecvq.append(recvq); - recvq.clear(); - return 1; + return ReadData(destrecvq); } // We should never reach this point. -- cgit v1.2.3