| 1 |
#include "tinput_handler.h" |
| 2 |
|
| 3 |
input_handler::input_handler (communicator &comm) |
| 4 |
: sender (comm) |
| 5 |
{ |
| 6 |
stdin_watcher.set (STDIN_FILENO, ev::READ); |
| 7 |
stdin_watcher.set<input_handler, &input_handler::stdin_read_cb> (this); |
| 8 |
stdin_watcher.start (); |
| 9 |
} |
| 10 |
|
| 11 |
input_handler::~input_handler () |
| 12 |
{ |
| 13 |
} |
| 14 |
|
| 15 |
void |
| 16 |
input_handler::stdin_read_cb (ev::io &w, int revents) |
| 17 |
{ |
| 18 |
char buf[BUFSIZ]; |
| 19 |
ssize_t len = read (w.fd, buf, sizeof buf); |
| 20 |
if (len < 0) |
| 21 |
throw "read error (stdin): " + std::string (strerror (errno)); |
| 22 |
if (len == 0) |
| 23 |
throw "EOF from stdin"; |
| 24 |
if (buf[0] == '/') |
| 25 |
send (buf + 1, size_t (len) - 2); |
| 26 |
else |
| 27 |
send ("command", std::string (buf, len - 1)); |
| 28 |
} |