server unittest for validating client request / new timeout cancellation handling (need refactoring)

This commit is contained in:
Benjamin Sergeant
2019-01-02 16:08:32 -08:00
parent c6adc00eac
commit 097c7e5397
10 changed files with 280 additions and 44 deletions

View File

@ -222,4 +222,30 @@ namespace ix
}
}
}
std::pair<bool, std::string> Socket::readLine(const CancellationRequest& isCancellationRequested)
{
// FIXME: N should be a parameter
// Read first line
const int N = 255;
char line[N+1];
int i;
for (i = 0; i < 2 || (i < N && line[i-2] != '\r' && line[i-1] != '\n'); ++i)
{
if (!readByte(line+i, isCancellationRequested))
{
return std::make_pair(false, std::string());
}
}
if (i == N)
{
return std::make_pair(false, std::string());
}
line[i] = 0;
return std::make_pair(true, std::string(line));
}
}