Skip to content
Snippets Groups Projects
Unverified Commit 46488d1b authored by Irene Zhang's avatar Irene Zhang Committed by GitHub
Browse files

Merge pull request #8 from mwhittaker/lockserver_client_fixes

A couple small lockserver client improvements.
parents 177425b0 679fcb9f
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,17 @@ ...@@ -30,6 +30,17 @@
#include "lockserver/client.h" #include "lockserver/client.h"
namespace {
void
usage()
{
printf("Unknown command.. Try again!\n");
printf("Usage: exit | q | lock <key> | unlock <key>\n");
}
} // namespace
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -68,14 +79,18 @@ main(int argc, char **argv) ...@@ -68,14 +79,18 @@ main(int argc, char **argv)
cmd[clen++] = c; cmd[clen++] = c;
cmd[clen] = '\0'; cmd[clen] = '\0';
if (clen == 0) continue;
tok = strtok(cmd, " ,.-"); tok = strtok(cmd, " ,.-");
if (tok == NULL) continue;
if (strcasecmp(tok, "exit") == 0 || strcasecmp(tok, "q") == 0) { if (strcasecmp(tok, "exit") == 0 || strcasecmp(tok, "q") == 0) {
printf("Exiting..\n"); printf("Exiting..\n");
break; break;
} else if (strcasecmp(tok, "lock") == 0) { } else if (strcasecmp(tok, "lock") == 0) {
tok = strtok(NULL, " ,.-"); tok = strtok(NULL, " ,.-");
if (tok == NULL) {
usage();
continue;
}
key = string(tok); key = string(tok);
status = locker.lock(key); status = locker.lock(key);
...@@ -86,11 +101,15 @@ main(int argc, char **argv) ...@@ -86,11 +101,15 @@ main(int argc, char **argv)
} }
} else if (strcasecmp(tok, "unlock") == 0) { } else if (strcasecmp(tok, "unlock") == 0) {
tok = strtok(NULL, " ,.-"); tok = strtok(NULL, " ,.-");
if (tok == NULL) {
usage();
continue;
}
key = string(tok); key = string(tok);
locker.unlock(key); locker.unlock(key);
printf("Unlock Successful\n"); printf("Unlock Successful\n");
} else { } else {
printf("Unknown command.. Try again!\n"); usage();
} }
fflush(stdout); fflush(stdout);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment