]> git.lyx.org Git - lyx.git/blobdiff - src/support/socktools.cpp
hand-crafted LyXErr
[lyx.git] / src / support / socktools.cpp
index 98fda7be93e791a6757d3143e334d7dafc98c8bd..662739f2720a16d5628fac0472c6cf14b92a723a 100644 (file)
@@ -50,7 +50,6 @@ int accept(int)
 
 #include <cerrno>
 
-using std::endl;
 using std::string;
 
 #ifndef CXX_GLOBAL_CSTD
@@ -82,8 +81,7 @@ int listen(FileName const & name, int queue)
        string::size_type len = localname.size();
        // the field sun_path in sockaddr_un is a char[108]
        if (len > 107) {
-               lyxerr << "lyx: Socket address '" << name.absFilename() << "' too long."
-                      << endl;
+               LYXERR0("lyx: Socket address '" << name.absFilename() << "' too long.");
                return -1;
        }
        // Synonims for AF_UNIX are AF_LOCAL and AF_FILE
@@ -96,15 +94,15 @@ int listen(FileName const & name, int queue)
        // For local sockets, the protocol is always 0
        // socket() returns -1 in case of error
        if ((fd = ::socket(PF_UNIX, SOCK_STREAM, 0))== -1) {
-               lyxerr << "lyx: Could not create socket descriptor: "
-                      << strerror(errno) << endl;
+               LYXERR0("lyx: Could not create socket descriptor: "
+                      << strerror(errno));
                return -1;
        }
 
        // Set NONBLOCK mode for the file descriptor
        if (::fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
-               lyxerr << "lyx: Could not set NONBLOCK mode for socket descriptor: "
-                    << strerror(errno) << endl;
+               LYXERR0("lyx: Could not set NONBLOCK mode for socket descriptor: "
+                    << strerror(errno));
                ::close(fd);
                return -1;
        }
@@ -113,10 +111,10 @@ int listen(FileName const & name, int queue)
        // the socket special file in the filesystem. bind() returns -1
        // in case of error
        if ((::bind (fd, reinterpret_cast<sockaddr *>(&addr), SUN_LEN(&addr))) == -1) {
-               lyxerr << "lyx: Could not bind address '" << name.absFilename()
-                      << "' to socket descriptor: " << strerror(errno) << endl;
+               LYXERR0("lyx: Could not bind address '" << name.absFilename()
+                      << "' to socket descriptor: " << strerror(errno));
                ::close(fd);
-               unlink(name);
+               name.removeFile();
                return -1;
        }
 
@@ -126,10 +124,10 @@ int listen(FileName const & name, int queue)
        // It is not a restriction on the number of connections the socket
        // can accept. Returns -1 in case of error
        if (::listen (fd, queue) == -1) {
-               lyxerr << "lyx: Could not put socket in 'listen' state: "
-                      << strerror(errno) << endl;
+               LYXERR0("lyx: Could not put socket in 'listen' state: "
+                      << strerror(errno));
                ::close(fd);
-               unlink(name);
+               name.removeFile();
                return -1;
        }
 
@@ -146,15 +144,15 @@ int accept(int sd)
        // Using null pointers for the second and third arguments
        // dismiss all information about the connecting client
        if ((fd = accept(sd, reinterpret_cast<sockaddr *>(0), reinterpret_cast<socklen_t *>(0))) == -1) {
-               lyxerr << "lyx: Could not accept connection: "
-                      << strerror(errno) << endl;
+               LYXERR0("lyx: Could not accept connection: "
+                      << strerror(errno));
                return -1;
        }
 
        // Sets NONBLOCK mode for the file descriptor
        if (::fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
-               lyxerr << "lyx: Could not set NONBLOCK mode for connection: "
-                      << strerror(errno) << endl;
+               LYXERR0("lyx: Could not set NONBLOCK mode for connection: "
+                      << strerror(errno));
                ::close(fd);
                return -1;
        }