mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Fixed FTP directory listing blocking forever if both expected responses are read from the command socket in a single call. (#1025)
This commit is contained in:
parent
556371ea10
commit
c15172e3fd
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user