forked from williame/hellepoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.cpp
43 lines (35 loc) · 868 Bytes
/
console.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* (c) William Edwards, 2011
Using the Simplified BSD License. See LICENSE file for details */
#include "console.hpp"
extern "C" {
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
}
void Console::create(Scheduler& scheduler) {
Console* self = new Console(scheduler);
self->construct();
}
Console::Console(Scheduler& scheduler): Task(scheduler) {}
void Console::do_construct() {
fd = fcntl(STDIN_FILENO,F_DUPFD,0);
schedule(EPOLLIN);
}
void Console::read() {
for(;;) {
if(!async_read_in(line))
return;
if(!strcasecmp("help\n",line.cstr())) {
printf("Available commands are:\n"
"\tquit\n");
} else if(!strcasecmp("quit\n",line.cstr())) {
ThrowShutdown("<goodbye>");
} else {
printf("Unknown command: try \"help\"\n");
}
line.clear();
}
}
void Console::dump_context(FILE* out) const {
fprintf(out,"Console ");
}