ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/tinput_handler.cpp
Revision: 1.2
Committed: Sun Oct 24 22:32:42 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
Changes since 1.1: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 sf-pippijn 1.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 sf-pippijn 1.2
21 sf-pippijn 1.1 if (len < 0)
22     throw "read error (stdin): " + std::string (strerror (errno));
23     if (len == 0)
24     throw "EOF from stdin";
25 sf-pippijn 1.2
26 sf-pippijn 1.1 if (buf[0] == '/')
27     send (buf + 1, size_t (len) - 2);
28     else
29     send ("command", std::string (buf, len - 1));
30     }