@@ -262,53 +262,50 @@ Socket::ReceiveData()
262262{
263263 char receivedBuf[DEFAULT_BUFLEN];
264264
265- while (true )
265+ const int receivedLen = recv (m_socket, receivedBuf, DEFAULT_BUFLEN, 0 );
266+ if (receivedLen > 0 )
266267 {
267- const int receivedLen = recv (m_socket, receivedBuf, DEFAULT_BUFLEN, 0 );
268- if (receivedLen > 0 )
268+ const std::string received (receivedBuf, receivedLen);
269+ std::istringstream receivedStream (received);
270+
271+ std::vector<std::vector<std::string>> receivedEntries;
272+ std::string receivedLine;
273+ while (std::getline (receivedStream, receivedLine))
269274 {
270- const std::string received (receivedBuf, receivedLen);
271- std::istringstream receivedStream (received) ;
275+ if (receivedLine. empty ())
276+ continue ;
272277
273- std::vector<std::vector<std::string>> receivedEntries;
274- std::string receivedLine;
275- while (std::getline (receivedStream, receivedLine))
278+ if (receivedLine.back () == ' \r ' )
276279 {
280+ receivedLine.pop_back (); // Remove carriage return
277281 if (receivedLine.empty ())
278282 continue ;
279-
280- if (receivedLine.back () == ' \r ' )
281- {
282- receivedLine.pop_back (); // Remove carriage return
283- if (receivedLine.empty ())
284- continue ;
285- }
286-
287- receivedEntries.push_back (StringSplit (std::move (receivedLine), " &" )); // Split data by "&" for easier parsing in certain cases
288283 }
289284
290- if (!s_logPingMessages && receivedEntries.empty ())
291- continue ;
285+ receivedEntries.push_back ( StringSplit ( std::move (receivedLine), " & " )); // Split data by "&" for easier parsing in certain cases
286+ }
292287
293- m_log << " [RECEIVED]: " << std::endl;
294- for (const std::vector<std::string>& receivedLineEntries : receivedEntries)
295- {
296- for (const std::string& entry : receivedLineEntries)
297- {
298- m_log << entry << std::endl;
299- }
300- m_log << std::endl;
301- }
302- m_log << ' \n ' << std::endl;
288+ if (!s_logPingMessages && receivedEntries.empty ())
289+ return {};
303290
304- return receivedEntries;
305- }
306- else if (receivedLen == 0 )
291+ m_log << " [RECEIVED]: " << std::endl;
292+ for (const std::vector<std::string>& receivedLineEntries : receivedEntries)
307293 {
308- throw ClientDisconnected ();
294+ for (const std::string& entry : receivedLineEntries)
295+ {
296+ m_log << entry << std::endl;
297+ }
298+ m_log << std::endl;
309299 }
310- throw std::runtime_error (" \" recv\" failed: " + std::to_string (WSAGetLastError ()));
300+ m_log << ' \n ' << std::endl;
301+
302+ return receivedEntries;
303+ }
304+ else if (receivedLen == 0 )
305+ {
306+ throw ClientDisconnected ();
311307 }
308+ throw std::runtime_error (" \" recv\" failed: " + std::to_string (WSAGetLastError ()));
312309}
313310
314311
0 commit comments