+ if (pipename.empty()) {
+ lyxerr[Debug::LYXSERVER]
+ << "LyXComm: server is disabled, nothing to do"
+ << endl;
+ return;
+ }
+
+ if ((infd = startPipe(inPipeName(), false)) == -1)
+ return;
+
+ if ((outfd = startPipe(outPipeName(), true)) == -1) {
+ endPipe(infd, inPipeName(), false);
+ return;
+ }
+
+ if (fcntl(outfd, F_SETFL, O_NONBLOCK) < 0) {
+ lyxerr << "LyXComm: Could not set flags on pipe " << outPipeName()
+ << '\n' << strerror(errno) << endl;
+ return;
+ }
+
+ // We made it!
+ ready = true;
+ lyxerr[Debug::LYXSERVER] << "LyXComm: Connection established" << endl;
+}
+
+
+/// Close pipes
+void LyXComm::closeConnection()
+{
+ lyxerr[Debug::LYXSERVER] << "LyXComm: Closing connection" << endl;
+
+ if (pipename.empty()) {
+ lyxerr[Debug::LYXSERVER]
+ << "LyXComm: server is disabled, nothing to do"
+ << endl;
+ return;
+ }
+
+ if (!ready) {
+ lyxerr << "LyXComm: Already disconnected" << endl;
+ return;
+ }
+
+ endPipe(infd, inPipeName(), false);
+ endPipe(outfd, outPipeName(), true);
+
+ ready = false;
+}
+
+
+int LyXComm::startPipe(string const & filename, bool write)
+{
+ int fd;
+