On Monday 02 September 2002 3:28 pm, John Levon wrote: > On Mon, Sep 02, 2002 at 02:55:59PM +0100, Angus Leeming wrote: > > if (rerrno == EAGAIN) { > > - errno = 0; > > - return; > > - } > > - if (rerrno != 0) { > > + break; > > + > > + } else if (rerrno != 0) { > > lyxerr << "LyXComm: " << strerror(rerrno) << > > endl; if (!lsbuf.empty()) { > > lyxerr << "LyXComm: truncated command: " > > << lsbuf << endl; > > lsbuf.erase(); > > } > > - break; // reset connection > > + > > + // reset connection > > + closeConnection(); > > + openConnection(); > > + break; > > } > > Hmm, surely EAGAIN is a perfectly reasonable return value, not an error > worthy of a printf
My point is that it's ridiculous to closeConnection(); openConnection(); in this case. I don't give a monkey about the print statement at the moment, although this (below) is semantically equivalent to the current code and far cleaner. However, I prefer a softly, softly approach to code that others may be more familiar with than me. Regards, Angus void LyXComm::read_alert() { read_buffer_.erase(); int const CMDBUFLEN = 100; char charbuf[CMDBUFLEN]; errno = 0; int status; // the single = is intended here. while ((status = ::read(infd, charbuf, CMDBUFLEN - 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()) { cerr << "Comm: truncated command: " << read_buffer_ << endl; read_buffer_.erase(); } // reset connection closeConnection(); openConnection(); break; } else { // errno == EAGAIN // Nothing new has arrived, so now's the time // to tell the outside world if there's anything // in the read buffer. break; } } if (!read_buffer_.empty()) { cerr << "Comm: Received from fd " << infd << '\n' << '\"' << read_buffer_ << '\"' << endl; // emit signal message_received(); } errno = 0; }