100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
3.4 KiB
C++
127 lines
3.4 KiB
C++
#include "minor_router.hpp"
|
|
#include <set>
|
|
namespace minorio {
|
|
std::uint64_t Router::aliases(const Session &value) const
|
|
{
|
|
std::uint64_t result = 0;
|
|
for (const auto &entry : handles_) {
|
|
if (entry.second.get() == &value) {
|
|
++result;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
DeviceInfo Router::describe(const Device &object) const
|
|
{
|
|
DeviceInfo result;
|
|
result.minor = object.minor;
|
|
result.generation = object.generation;
|
|
result.capacity = object.capacity;
|
|
result.length = object.data.size();
|
|
std::set<const Session *> seen;
|
|
for (const auto &entry : handles_) {
|
|
const auto &value = *entry.second;
|
|
if (value.object.get() == &object) {
|
|
++result.handles;
|
|
seen.insert(&value);
|
|
}
|
|
}
|
|
result.sessions = seen.size();
|
|
return result;
|
|
}
|
|
SessionInfo Router::describe(int fd, const Session &value) const
|
|
{
|
|
SessionInfo result;
|
|
result.fd = fd;
|
|
result.minor = value.object->minor;
|
|
result.generation = value.object->generation;
|
|
result.capacity = value.object->capacity;
|
|
result.length = value.object->data.size();
|
|
result.cursor = value.cursor;
|
|
result.mode = value.mode;
|
|
result.append = value.append ? 1 : 0;
|
|
result.linked = value.object->linked ? 1 : 0;
|
|
result.aliases = aliases(value);
|
|
return result;
|
|
}
|
|
std::vector<std::shared_ptr<Router::Device>> Router::objects() const
|
|
{
|
|
std::vector<std::shared_ptr<Device>> result;
|
|
std::set<const Device *> seen;
|
|
for (const auto &entry : routes_) {
|
|
const auto &object = entry.second;
|
|
if (seen.insert(object.get()).second) {
|
|
result.push_back(object);
|
|
}
|
|
}
|
|
for (const auto &entry : handles_) {
|
|
const auto &object = entry.second->object;
|
|
if (seen.insert(object.get()).second) {
|
|
result.push_back(object);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
int Router::device(int minor, DeviceInfo &out) const
|
|
{
|
|
if (!valid_minor(minor)) {
|
|
return -22;
|
|
}
|
|
const auto object = route(minor);
|
|
if (!object) {
|
|
return -2;
|
|
}
|
|
const auto result = describe(*object);
|
|
out = result;
|
|
return 0;
|
|
}
|
|
int Router::session(int fd, SessionInfo &out) const
|
|
{
|
|
const auto value = find_session(fd);
|
|
if (!value) {
|
|
return -9;
|
|
}
|
|
const auto result = describe(fd, *value);
|
|
out = result;
|
|
return 0;
|
|
}
|
|
void Router::devices(std::vector<DeviceInfo> &out) const
|
|
{
|
|
std::vector<DeviceInfo> result;
|
|
result.reserve(routes_.size());
|
|
for (const auto &entry : routes_) {
|
|
result.push_back(describe(*entry.second));
|
|
}
|
|
out.swap(result);
|
|
}
|
|
void Router::sessions(std::vector<SessionInfo> &out) const
|
|
{
|
|
std::vector<SessionInfo> result;
|
|
result.reserve(handles_.size());
|
|
for (const auto &entry : handles_) {
|
|
result.push_back(describe(entry.first, *entry.second));
|
|
}
|
|
out.swap(result);
|
|
}
|
|
Counts Router::counts() const
|
|
{
|
|
Counts result;
|
|
result.linked = routes_.size();
|
|
result.handles = handles_.size();
|
|
std::set<const Session *> seen;
|
|
for (const auto &entry : handles_) {
|
|
seen.insert(entry.second.get());
|
|
}
|
|
result.sessions = seen.size();
|
|
const auto retained = objects();
|
|
for (const auto &object : retained) {
|
|
if (!object->linked) {
|
|
++result.retired;
|
|
}
|
|
result.bytes += object->data.size();
|
|
result.capacity += object->capacity;
|
|
}
|
|
return result;
|
|
}
|
|
}
|