]> git.lyx.org Git - lyx.git/blobdiff - src/lyxsocket.C
minimal effort implementation of:
[lyx.git] / src / lyxsocket.C
index 9bd4c5f9fd4a475d31391914f04d6a4e8971819d..5755bb6dcf3271eda7432bef3a528671a3acfb1e 100644 (file)
 
 #include <cerrno>
 
+#if defined (_WIN32)
+# include <io.h>
+#endif
+
 using boost::shared_ptr;
 
 using std::auto_ptr;
@@ -70,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;
 }
@@ -159,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
@@ -197,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."
@@ -215,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
@@ -254,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