MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / allocateResponseBuffer

Method allocateResponseBuffer

Libraries/HttpClient/HttpClient.cpp:1408–1446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1406}
1407
1408SC::Result SC::HttpClientOperation::allocateResponseBuffer(size_t minimumSizeInBytes, size_t& bufferIndex,
1409 Span<char>& data)
1410{
1411 eventMutex.lock();
1412 bool supportsSize = false;
1413 for (const HttpClientResponseBuffer& buffer : responseBuffers)
1414 {
1415 if (buffer.data.sizeInBytes() >= minimumSizeInBytes)
1416 {
1417 supportsSize = true;
1418 break;
1419 }
1420 }
1421 if (not supportsSize)
1422 {
1423 eventMutex.unlock();
1424 return Result::Error("HttpClient: response buffer exhausted");
1425 }
1426
1427 while (requestInFlight)
1428 {
1429 for (size_t idx = 0; idx < responseBuffers.sizeInElements(); ++idx)
1430 {
1431 HttpClientResponseBuffer& buffer = responseBuffers[idx];
1432 if (not buffer.inUse and buffer.data.sizeInBytes() >= minimumSizeInBytes)
1433 {
1434 buffer.inUse = true;
1435 bufferIndex = idx;
1436 data = buffer.data;
1437 eventMutex.unlock();
1438 return Result(true);
1439 }
1440 }
1441 eventCV.wait(eventMutex);
1442 }
1443
1444 eventMutex.unlock();
1445 return Result::Error("HttpClient: request cancelled");
1446}
1447
1448void SC::HttpClientOperation::releaseResponseBuffer(size_t bufferIndex)
1449{

Callers

nothing calls this directly

Calls 6

ErrorEnum · 0.50
ResultClass · 0.50
lockMethod · 0.45
sizeInBytesMethod · 0.45
unlockMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected