Reads a single response line from the server control channel. @param[out] strResponse Response of the server as string.
| 1218 | /// Reads a single response line from the server control channel. |
| 1219 | /// @param[out] strResponse Response of the server as string. |
| 1220 | bool CFTPClient::GetSingleResponseLine(tstring& strResponse) const |
| 1221 | { |
| 1222 | if( !IsConnected() ) |
| 1223 | return false; |
| 1224 | |
| 1225 | try |
| 1226 | { |
| 1227 | if( m_qResponseBuffer.empty() ) |
| 1228 | { |
| 1229 | // internal buffer is empty ==> get response from FTP server |
| 1230 | int iNum=0; |
| 1231 | std::string strTemp; |
| 1232 | |
| 1233 | do |
| 1234 | { |
| 1235 | iNum=m_apSckControlConnection->Receive(&(*m_vBuffer.begin()), static_cast<int>(m_vBuffer.size())-1, mc_uiTimeout); |
| 1236 | if( mc_uiResponseWait !=0 ) |
| 1237 | Sleep(mc_uiResponseWait); |
| 1238 | m_vBuffer[iNum] = '\0'; |
| 1239 | strTemp+=&(*m_vBuffer.begin()); |
| 1240 | } while( iNum==static_cast<int>(m_vBuffer.size())-1 && m_apSckControlConnection->CheckReadability() ); |
| 1241 | |
| 1242 | // each line in response is a separate entry in the internal buffer |
| 1243 | while( strTemp.length() ) |
| 1244 | { |
| 1245 | size_t iCRLF=strTemp.find('\n'); |
| 1246 | if( iCRLF != std::string::npos ) |
| 1247 | { |
| 1248 | m_qResponseBuffer.push(strTemp.substr(0, iCRLF+1)); |
| 1249 | strTemp.erase(0, iCRLF+1); |
| 1250 | } |
| 1251 | else |
| 1252 | { |
| 1253 | // this is not rfc standard; normally each command must end with CRLF |
| 1254 | // in this case it doesn't |
| 1255 | m_qResponseBuffer.push(strTemp); |
| 1256 | strTemp.clear(); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | if( m_qResponseBuffer.empty() ) |
| 1261 | return false; |
| 1262 | } |
| 1263 | |
| 1264 | // get first response-line from buffer |
| 1265 | strResponse = CCnv::ConvertToTString(m_qResponseBuffer.front().c_str()); |
| 1266 | m_qResponseBuffer.pop(); |
| 1267 | |
| 1268 | // remove CrLf if exists (don't use mc_strEolCharacterSequence here) |
| 1269 | if( strResponse.length()> 1 && strResponse.substr(strResponse.length()-2)==_T("\r\n") ) |
| 1270 | strResponse.erase(strResponse.length()-2, 2); |
| 1271 | } |
| 1272 | catch(CBlockingSocketException& blockingException) |
| 1273 | { |
| 1274 | ReportError(blockingException.GetErrorMessage(), CCnv::ConvertToTString(__FILE__), __LINE__); |
| 1275 | const_cast<CFTPClient*>(this)->m_apSckControlConnection->Cleanup(); |
| 1276 | return false; |
| 1277 | } |
nothing calls this directly
no test coverage detected