ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/tinput_handler.cpp
Revision: 1.1
Committed: Sun Oct 24 22:24:50 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
Log Message:
added a command line client (no curses)

File Contents

# Content
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 }