Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ctrl+c problem in cli mode. #286

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/observer/common/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
20 changes: 6 additions & 14 deletions src/observer/net/cli_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/observer/net/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,14 @@ int Server::start_stdin_server()
SessionEvent *event = nullptr;
leauny marked this conversation as resolved.
Show resolved Hide resolved
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_) {
leauny marked this conversation as resolved.
Show resolved Hide resolved
break;
}

Expand Down
Loading