#else // defined (HAVE_FCNTL)
-#include "support/lyxlib.h"
-
-#include "debug.h"
+#include "support/debug.h"
#include <sys/socket.h>
#include <sys/un.h>
#endif
#include <cerrno>
+#include <string>
-using std::endl;
-using std::string;
+using namespace std;
-#ifndef CXX_GLOBAL_CSTD
-using std::strerror;
-#endif
// This MACRO eppears to be defined only on Linux.
#if !defined(SUN_LEN)
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
// 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;
}
// 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;
}
// 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;
}
// 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;
}