mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
fix(control): handle all keys of one input in interactive mode
- The REPL polled the stdin fd, then read one key with std::cin; the other keys of the same read stayed in the std::cin buffer, and poll() did not report them again - Read one key with read(2), so poll() reports each key that is not handled yet; skip whitespace, as operator>> did - Stop reading at end of input: before, a closed stdin (e.g. < /dev/null) made the loop print the help without a pause - Enable ControlPlugin.SeveralKeysInOneInput - Update the documentation pages that described the defect, and the source line links into the changed files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <fairmq/tools/IO.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cctype> // isspace
|
||||
#include <chrono>
|
||||
#include <csignal> // catching system signals
|
||||
#include <cstdlib>
|
||||
@@ -19,6 +20,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include <poll.h> // for the interactive mode
|
||||
#include <unistd.h> // read
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -172,12 +174,21 @@ auto Control::RunREPL() -> void
|
||||
bool keepRunning = true;
|
||||
|
||||
while (keepRunning) {
|
||||
if (poll(cinfd, 1, 100)) {
|
||||
if (poll(cinfd, 1, 100) > 0) {
|
||||
if (fDeviceShutdownRequested) {
|
||||
break;
|
||||
}
|
||||
|
||||
cin >> input;
|
||||
// read() without a buffer: poll() then sees each key that is not handled yet
|
||||
auto const n = read(cinfd[0].fd, &input, 1);
|
||||
if (n == 0) {
|
||||
LOG(debug) << "End of input on stdin, interactive control stops reading keys";
|
||||
cinfd[0].fd = -1; // poll() ignores a negative fd
|
||||
continue;
|
||||
}
|
||||
if (n < 0 || isspace(static_cast<unsigned char>(input))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (input) {
|
||||
case 'c':
|
||||
|
||||
Reference in New Issue
Block a user