diff --git a/src/observer/common/rc.h b/src/observer/common/rc.h index 9acc27651..76583838c 100644 --- a/src/observer/common/rc.h +++ b/src/observer/common/rc.h @@ -28,6 +28,7 @@ See the Mulan PSL v2 for more details. */ DEFINE_RC(NOMEM) \ DEFINE_RC(NOTFOUND) \ DEFINE_RC(EMPTY) \ + DEFINE_RC(EMPTY_CMD) \ DEFINE_RC(BUFFERPOOL_OPEN) \ DEFINE_RC(BUFFERPOOL_NOBUF) \ DEFINE_RC(BUFFERPOOL_INVALID_PAGE_NUM) \ diff --git a/src/observer/net/cli_communicator.cpp b/src/observer/net/cli_communicator.cpp index 7e34e9f9a..846c3f7d4 100644 --- a/src/observer/net/cli_communicator.cpp +++ b/src/observer/net/cli_communicator.cpp @@ -86,19 +86,6 @@ bool is_exit_command(const char *cmd) { 0 == strncasecmp("\\q", cmd, 2) ; } -char *read_command() -{ - const char *prompt_str = "miniob > "; - char *input_command = nullptr; - for (input_command = my_readline(prompt_str); - common::is_blank(input_command); - input_command = my_readline(prompt_str)) { - free(input_command); - input_command = nullptr; - } - return input_command; -} - RC CliCommunicator::init(int fd, Session *session, const std::string &addr) { RC rc = PlainCommunicator::init(fd, session, addr); @@ -126,7 +113,12 @@ RC CliCommunicator::init(int fd, Session *session, const std::string &addr) RC CliCommunicator::read_event(SessionEvent *&event) { event = nullptr; - char *command = read_command(); + char *command = my_readline("miniob > "); + if (common::is_blank(command)) { + free(command); + event = nullptr; + return RC::EMPTY_CMD; + } if (is_exit_command(command)) { free(command); diff --git a/src/observer/net/server.cpp b/src/observer/net/server.cpp index e6692aa6e..63160c39f 100644 --- a/src/observer/net/server.cpp +++ b/src/observer/net/server.cpp @@ -323,11 +323,14 @@ int Server::start_stdin_server() SessionEvent *event = nullptr; rc = communicator->read_event(event); if (OB_FAIL(rc)) { + if (rc == RC::EMPTY_CMD) { + continue; + } LOG_WARN("failed to read event. rc=%s", strrc(rc)); return -1; } - if (event == nullptr) { + if (event == nullptr || !started_) { break; }