Attached is a patch to LyXComm:read_ready that enables the
LyXServer to work coherently with Tru64 unix. It's little more
than a clean-up of the existing code and does not change the
resulting string passed to the LyXServer /at all/.
It transpires that the root of the problems lies in
int select(
int nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
struct timeval *timeout) ;
that lies at the heart of fl_watch_io. The Tru64 version behaves
differently to that on Linux boxes, returning a +ve value if a
pipe is not connected "at both ends", ie by a read and a write
file descriptor.
I'll apply this patch if no-one says not to.
Angus
Index: src/lyxserver.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxserver.C,v
retrieving revision 1.45
diff -u -p -r1.45 lyxserver.C
--- src/lyxserver.C 14 Aug 2002 21:22:29 -0000 1.45
+++ src/lyxserver.C 11 Sep 2002 15:39:49 -0000
@@ -257,56 +257,54 @@ void LyXComm::emergencyCleanup()
// Receives messages and sends then to client
void LyXComm::read_ready()
{
- if (lyxerr.debugging(Debug::LYXSERVER)) {
- lyxerr << "LyXComm: Receiving from fd " << infd << endl;
- }
+ // nb! make read_buffer_ a class-member for multiple sessions
+ static string read_buffer_;
+ read_buffer_.erase();
- int const CMDBUFLEN = 100;
- char charbuf[CMDBUFLEN];
- string cmd;
-// nb! make lsbuf a class-member for multiple sessions
- static string lsbuf;
+ int const charbuf_size = 100;
+ char charbuf[charbuf_size];
errno = 0;
int status;
// the single = is intended here.
- while ((status = read(infd, charbuf, CMDBUFLEN - 1))) {
- int rerrno = errno;
-
+ while ((status = ::read(infd, charbuf, charbuf_size - 1))) {
+
if (status > 0) {
- charbuf[status]= '\0'; // turn it into a c string
- lsbuf += rtrim(charbuf, "\r");
- // commit any commands read
- while (lsbuf.find('\n') != string::npos) {
- // 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())
- clientcb(client, cmd);
- //\n or not \n?
- }
- }
- if (rerrno == EAGAIN) {
- errno = 0;
- return;
- }
- if (rerrno != 0) {
- lyxerr << "LyXComm: " << strerror(rerrno) << endl;
- if (!lsbuf.empty()) {
+ 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: "
- << lsbuf << endl;
- lsbuf.erase();
+ << read_buffer_ << '\n'
+ << "Resetting connection" << endl;
+ read_buffer_.erase();
}
- break; // reset connection
+
+ // 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;
}
}
- closeConnection();
- openConnection();
- errno= 0;
+
+ if (!read_buffer_.empty()) {
+ read_buffer_ = rtrim(read_buffer_, "\n");
+ lyxerr[Debug::LYXSERVER]
+ << "LyXComm: Received from fd "
+ << infd << '\n'
+ << '\"' << read_buffer_ << '\"' << endl;
+ clientcb(client, read_buffer_);
+ }
+
+ errno = 0;
}