- while ((status = read(fd, charbuf, CMDBUFLEN-1)))
- {// break and return in loop
- if (status > 0) // got something
- {
- charbuf[status]= '\0'; // turn it into a c string
- lsbuf += strip(charbuf, '\r');
- // commit any commands read
- while (lsbuf.find('\n') != string::npos) // while still
- // commands
- // left
- {
- // split() grabs the entire string if
- // the delim /wasn't/ found. ?:-P
- lsbuf= split(lsbuf, cmd,'\n');
- lyxerr[Debug::LYXSERVER]
- << "LyXComm: status:" << status
- << ", lsbuf:" << lsbuf
- << ", cmd:" << cmd << endl;
- if (!cmd.empty())
- c->clientcb(c->client, cmd);
- //\n or not \n?
+ while ((status = ::read(infd, charbuf, charbuf_size - 1))) {
+
+ if (status > 0) {
+ charbuf[status] = '\0'; // turn it into a c string
+ read_buffer_ += rtrim(charbuf, "\r");
+
+ } else if (errno != EAGAIN) {
+ if (!read_buffer_.empty()) {
+ lyxerr << "LyXComm: truncated command: "
+ << read_buffer_ << '\n'
+ << "Resetting connection" << endl;
+ read_buffer_.erase();