Check for timed out sessions and old reply buffers static*/
| 1573 | |
| 1574 | // Check for timed out sessions and old reply buffers |
| 1575 | /*static*/ void HttpResponder::CheckSessions() noexcept |
| 1576 | { |
| 1577 | unsigned int clientsTimedOut = 0; |
| 1578 | const uint32_t now = millis(); |
| 1579 | for (size_t i = numSessions; i != 0; ) |
| 1580 | { |
| 1581 | --i; |
| 1582 | if (now - sessions[i].lastQueryTime > HttpSessionTimeout) |
| 1583 | { |
| 1584 | RemoveSession(i); |
| 1585 | clientsTimedOut++; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | // If we cannot send the G-Code reply to anyone, we may free up some run-time space by dumping it |
| 1590 | if (clientsTimedOut != 0) |
| 1591 | { |
| 1592 | bool released = false; |
| 1593 | { |
| 1594 | MutexLocker lock(gcodeReplyMutex); |
| 1595 | |
| 1596 | clientsServed += clientsTimedOut; // assume the disconnected clients haven't fetched the G-Code reply yet |
| 1597 | if (numSessions == 0 || clientsServed >= numSessions) |
| 1598 | { |
| 1599 | while (!gcodeReply.IsEmpty()) |
| 1600 | { |
| 1601 | OutputBuffer *buf = gcodeReply.Pop(); |
| 1602 | OutputBuffer::ReleaseAll(buf); |
| 1603 | } |
| 1604 | released = true; |
| 1605 | } |
| 1606 | clientsServed = 0; |
| 1607 | } |
| 1608 | if (released && reprap.Debug(Module::Webserver)) |
| 1609 | { |
| 1610 | debugPrintf("Released gcodeReply, free buffers=%u\n", OutputBuffer::GetFreeBuffers()); |
| 1611 | } |
| 1612 | } |
| 1613 | else if (!gcodeReply.IsEmpty()) |
| 1614 | { |
| 1615 | // Check whether we can time out any GCode buffers |
| 1616 | bool released; |
| 1617 | { |
| 1618 | MutexLocker lock(gcodeReplyMutex); |
| 1619 | released = gcodeReply.ApplyTimeout(HttpSessionTimeout); |
| 1620 | } |
| 1621 | if (released && reprap.Debug(Module::Webserver)) |
| 1622 | { |
| 1623 | debugPrintf("Timed out gcodeReply, free buffers=%u\n", OutputBuffer::GetFreeBuffers()); |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | /*static*/ void HttpResponder::CommonDiagnostics(const StringRef& reply) noexcept |
| 1629 | { |
nothing calls this directly
no test coverage detected