X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxsocket.C;h=4af70e10b22c66843a39c08d009995862c1e72d2;hb=368f6a53a87eb5997433ecd0f51e854c99360d28;hp=73f8b210694e6467c7a7075bc31c6750bf1f6c7c;hpb=201e5bdf707317be29e9b7476e2b97a34e2d0b48;p=lyx.git diff --git a/src/lyxsocket.C b/src/lyxsocket.C index 73f8b21069..4af70e10b2 100644 --- a/src/lyxsocket.C +++ b/src/lyxsocket.C @@ -14,66 +14,8 @@ #include -#include - #include "lyxsocket.h" - -#if !(defined(HAVE_READ) && defined(HAVE_WRITE) && defined(HAVE_CLOSE)) -// We provide stub classes to disables the sockets. - -LyXServerSocket::LyXServerSocket(LyXFunc *, std::string const &) -{} - - -LyXServerSocket::~LyXServerSocket() -{} - - -std::string const & LyXServerSocket::address() const -{ - return address_; -} - - -void LyXServerSocket::serverCallback() -{} - - -void LyXServerSocket::dataCallback(int) -{} - - -void LyXServerSocket::writeln(std::string const &) -{} - - -LyXDataSocket::LyXDataSocket(int) -{} - - -LyXDataSocket::~LyXDataSocket() -{} - - -bool LyXDataSocket::connected() const -{ - return false; -} - - -bool LyXDataSocket::readln(std::string &) -{ - return false; -} - - -void LyXDataSocket::writeln(std::string const &) -{} - -#else // defined(HAVE_READ) && defined(HAVE_WRITE) && defined(HAVE_CLOSE) - - #include "debug.h" #include "funcrequest.h" #include "LyXAction.h" @@ -89,6 +31,10 @@ void LyXDataSocket::writeln(std::string const &) #include +#if defined (_WIN32) +# include +#endif + using boost::shared_ptr; using std::auto_ptr; @@ -128,8 +74,12 @@ LyXServerSocket::LyXServerSocket(LyXFunc * f, string const & addr) // Close the socket and remove the address of the filesystem. LyXServerSocket::~LyXServerSocket() { - lyx_gui::unregister_socket_callback(fd_); - ::close(fd_); + if (fd_ != -1) { + lyx_gui::unregister_socket_callback(fd_); + if (::close(fd_) != 0) + lyxerr << "lyx: Server socket " << fd_ + << " IO error on closing: " << strerror(errno); + } lyx::support::unlink(address_); lyxerr[Debug::LYXSERVER] << "lyx: Server socket quitting" << endl; } @@ -190,7 +140,7 @@ void LyXServerSocket::dataCallback(int fd) if (key == "LYXCMD") { string const cmd = line.substr(pos + 1); func->dispatch(lyxaction.lookupFunc(cmd)); - string const rval = func->getMessage(); + string const rval = lyx::to_utf8(func->getMessage()); if (func->errorStat()) { client->writeln("ERROR:" + cmd + ':' + rval); } else { @@ -217,7 +167,7 @@ void LyXServerSocket::writeln(string const & line) string const linen(line + '\n'); int const size = linen.size(); int const written = ::write(fd_, linen.c_str(), size); - if (written < size) { // Allways mean end of connection. + if (written < size) { // Always mean end of connection. if ((written == -1) && (errno == EPIPE)) { // The program will also receive a SIGPIPE // that must be caught @@ -255,7 +205,9 @@ LyXDataSocket::LyXDataSocket(int fd) LyXDataSocket::~LyXDataSocket() { - ::close(fd_); + if (::close(fd_) != 0) + lyxerr << "lyx: Data socket " << fd_ + << " IO error on closing: " << strerror(errno); lyx_gui::unregister_socket_callback(fd_); lyxerr[Debug::LYXSERVER] << "lyx: Data socket " << fd_ << " quitting." @@ -273,7 +225,7 @@ bool LyXDataSocket::connected() const bool LyXDataSocket::readln(string & line) { int const charbuf_size = 100; - char charbuf[charbuf_size]; // buffer for the ::read() system call + char charbuf[charbuf_size]; // buffer for the ::read() system call int count; // read and store characters in buffer @@ -312,7 +264,7 @@ void LyXDataSocket::writeln(string const & line) string const linen(line + '\n'); int const size = linen.size(); int const written = ::write(fd_, linen.c_str(), size); - if (written < size) { // Allways mean end of connection. + if (written < size) { // Always mean end of connection. if ((written == -1) && (errno == EPIPE)) { // The program will also receive a SIGPIPE // that must be catched @@ -328,5 +280,3 @@ void LyXDataSocket::writeln(string const & line) connected_ = false; } } - -#endif // defined(HAVE_READ) && defined(HAVE_WRITE) && defined(HAVE_CLOSE)