diff options
Diffstat (limited to 'src/SFML/Network/Ftp.cpp')
-rw-r--r-- | src/SFML/Network/Ftp.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 44a03b8..9415335 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -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<Response::Status>(code), message); } |