From 5843696fe99457523f27606f41e0bac584dd4791 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 12 Nov 2001 17:43:21 +0000 Subject: [PATCH] fixes to lyxserver from John git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3012 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++++ src/lyxserver.C | 27 +++++++++++++++------------ src/lyxserver.h | 12 +++++++++++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f2b2dd7646..9879aa62fb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2001-11-12 John Levon + + * lyxserver.h: + * lyxserver.C: fix it. and small cleanup. + 2001-11-07 John Levon * BufferView_pimpl.C: use inline helpers diff --git a/src/lyxserver.C b/src/lyxserver.C index ab129d5755..3e16f06138 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -110,16 +110,16 @@ void LyXComm::openConnection() if (pipename.empty()) return; - if ((infd = startPipe(pipename + ".in")) == -1) + if ((infd = startPipe(inPipeName(), false)) == -1) return; - if ((outfd = startPipe(pipename + ".out")) == -1) { - endPipe(infd, pipename + ".in"); + if ((outfd = startPipe(outPipeName(), true)) == -1) { + endPipe(infd, inPipeName()); return; } if (fcntl(outfd, F_SETFL, O_NONBLOCK) < 0) { - lyxerr << "LyXComm: Could not set flags on pipe " << pipename << ".out" + lyxerr << "LyXComm: Could not set flags on pipe " << outPipeName() << '\n' << strerror(errno) << endl; return; } @@ -144,13 +144,13 @@ void LyXComm::closeConnection() return; } - endPipe(infd, pipename + ".in"); - endPipe(outfd, pipename + ".out"); + endPipe(infd, inPipeName()); + endPipe(outfd, outPipeName()); ready = false; } -int LyXComm::startPipe(string const & filename) +int LyXComm::startPipe(string const & filename, bool write) { int fd; @@ -201,7 +201,7 @@ int LyXComm::startPipe(string const & filename) << strerror(errno) << endl; return -1; }; - fd = ::open(filename.c_str(), O_RDONLY|O_NONBLOCK); + fd = ::open(filename.c_str(), write ? (O_RDWR) : (O_RDONLY|O_NONBLOCK)); #endif if (fd < 0) { @@ -210,7 +210,10 @@ int LyXComm::startPipe(string const & filename) lyx::unlink(filename); return -1; } - fl_add_io_callback(fd, FL_READ, C_LyXComm_callback, this); + + if (!write) + fl_add_io_callback(fd, FL_READ, C_LyXComm_callback, this); + return fd; } @@ -252,8 +255,8 @@ void LyXComm::endPipe(int & fd, string const & filename) void LyXComm::emergencyCleanup() { - endPipe(infd, pipename + ".in"); - endPipe(outfd, pipename + ".out"); + endPipe(infd, inPipeName()); + endPipe(outfd, outPipeName()); } @@ -399,7 +402,7 @@ void LyXServer::callback(LyXServer * serv, string const & msg) if (compare(p, "LYXSRV:", 7) == 0) { server_only = true; } else if (0 != compare(p, "LYXCMD:", 7)) { - lyxerr << "LyXServer: Unknown request" << endl; + lyxerr << "LyXServer: Unknown request \"" << p << "\"" << endl; return; } p += 7; diff --git a/src/lyxserver.h b/src/lyxserver.h index 866cda07e4..4952411b1f 100644 --- a/src/lyxserver.h +++ b/src/lyxserver.h @@ -59,6 +59,16 @@ public: static void callback(int fd, void *v); private: + /// the filename of the in pipe + string const inPipeName() { + return pipename + ".in"; + } + + /// the filename of the out pipe + string const outPipeName() { + return pipename + ".out"; + } + /// Open pipes void openConnection(); @@ -66,7 +76,7 @@ private: void closeConnection(); /// start a pipe - int startPipe(string const &); + int startPipe(string const &, bool); /// finish a pipe void endPipe(int &, string const &); -- 2.39.2