diff --git a/include/SFML/Network/Ftp.hpp b/include/SFML/Network/Ftp.hpp index c62db7ba2..93b6502ac 100644 --- a/include/SFML/Network/Ftp.hpp +++ b/include/SFML/Network/Ftp.hpp @@ -529,7 +529,8 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - TcpSocket m_commandSocket; ///< Socket holding the control connection with the server + TcpSocket m_commandSocket; ///< Socket holding the control connection with the server + std::string m_receiveBuffer; ///< Received command data that is yet to be processed }; } // namespace sf diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 44a03b8b3..80688e566 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -395,8 +395,18 @@ Ftp::Response Ftp::getResponse() // Receive the response from the server char buffer[1024]; std::size_t length; - if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Done) - return Response(Response::ConnectionClosed); + + if (m_receiveBuffer.empty()) + { + if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Done) + return Response(Response::ConnectionClosed); + } + else + { + std::copy(m_receiveBuffer.begin(), m_receiveBuffer.end(), buffer); + length = m_receiveBuffer.size(); + m_receiveBuffer.clear(); + } // There can be several lines inside the received buffer, extract them all std::istringstream in(std::string(buffer, length), std::ios_base::binary); @@ -452,6 +462,9 @@ Ftp::Response Ftp::getResponse() message = separator + line; } + // Save the remaining data for the next time getResponse() is called + m_receiveBuffer.assign(buffer + in.tellg(), length - in.tellg()); + // Return the response code and message return Response(static_cast(code), message); }