#include <config.h>
#include "debug.h"
+#include "support/filename.h"
#include "support/unicode.h"
#include "support/lstrings.h"
namespace lyx {
-using lyx::support::prefixIs;
+using support::FileName;
+using support::prefixIs;
using boost::scoped_ptr;
namespace fs = boost::filesystem;
/// Connect to the socket \p name.
-/// Caution: \p name is in filesystem encoding
-int connect(string const & name)
+int connect(FileName const & name)
{
int fd; // File descriptor for the socket
sockaddr_un addr; // Structure that hold the socket address
+ string const encoded = name.toFilesystemEncoding();
// char sun_path[108]
- string::size_type len = name.size();
+ string::size_type len = encoded.size();
if (len > 107) {
cerr << "lyxclient: Socket address '" << name
<< "' too long." << endl;
}
// Synonims for AF_UNIX are AF_LOCAL and AF_FILE
addr.sun_family = AF_UNIX;
- name.copy(addr.sun_path, 107);
+ encoded.copy(addr.sun_path, 107);
addr.sun_path[len] = '\0';
if ((fd = ::socket(PF_UNIX, SOCK_STREAM, 0))== -1) {
if (::connect(fd,
reinterpret_cast<struct sockaddr *>(&addr),
sizeof(addr)) == -1) {
- cerr << "lyxclient: Could not connect to socket " << name
+ cerr << "lyxclient: Could not connect to socket " << name.absFilename()
<< ": " << strerror(errno) << endl;
::close(fd);
return -1;
// Modified LyXDataSocket class for use with the client
class LyXDataSocket {
public:
- LyXDataSocket(string const &);
+ LyXDataSocket(FileName const &);
~LyXDataSocket();
// File descriptor of the connection
int fd() const;
};
-LyXDataSocket::LyXDataSocket(string const & address)
+LyXDataSocket::LyXDataSocket(FileName const & address)
{
if ((fd_ = support::socktools::connect(address)) == -1) {
connected_ = false;
scoped_ptr<LyXDataSocket> server;
if (!cmdline::serverAddress.empty()) {
- server.reset(new LyXDataSocket(to_utf8(cmdline::serverAddress)));
+ server.reset(new LyXDataSocket(FileName(to_utf8(cmdline::serverAddress))));
if (!server->connected()) {
cerr << "lyxclient: " << "Could not connect to "
<< to_utf8(cmdline::serverAddress) << endl;
} else {
// We have to look for an address.
// serverPid can be empty.
- vector<fs::path> addrs = support::lyxSockets(to_utf8(cmdline::mainTmp), cmdline::serverPid);
+ vector<fs::path> addrs = support::lyxSockets(to_filesystem8bit(cmdline::mainTmp), cmdline::serverPid);
vector<fs::path>::const_iterator addr = addrs.begin();
vector<fs::path>::const_iterator end = addrs.end();
for (; addr != end; ++addr) {
// Caution: addr->string() is in filesystem encoding
- server.reset(new LyXDataSocket(addr->string()));
+ server.reset(new LyXDataSocket(FileName(to_utf8(from_filesystem8bit(addr->string())))));
if (server->connected())
break;
lyxerr << "lyxclient: " << "Could not connect to "
// such that package().temp_dir() is properly initialized.
pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_,
- package().temp_dir().absFilename() + "/lyxsocket"));
+ FileName(package().temp_dir().absFilename() + "/lyxsocket")));
// Start the real execution loop.
exit_status = pimpl_->application_->exec();
// Address is the unix address for the socket.
// MAX_CLIENTS is the maximum number of clients
// that can connect at the same time.
-LyXServerSocket::LyXServerSocket(LyXFunc * f, string const & addr)
+LyXServerSocket::LyXServerSocket(LyXFunc * f, support::FileName const & addr)
: func(f),
fd_(support::socktools::listen(addr, 3)),
address_(addr)
// Needed by xdvi
support::setEnv("XEDITOR", "lyxclient -g %f %l");
// Needed by lyxclient
- support::setEnv("LYXSOCKET", address_);
+ support::setEnv("LYXSOCKET", address_.toFilesystemEncoding());
theApp()->registerSocketCallback(
fd_,
);
LYXERR(Debug::LYXSERVER) << "lyx: New server socket "
- << fd_ << ' ' << address_ << endl;
+ << fd_ << ' ' << address_.absFilename() << endl;
}
lyxerr << "lyx: Server socket " << fd_
<< " IO error on closing: " << strerror(errno);
}
- support::unlink(support::FileName(address_));
+ support::unlink(address_);
LYXERR(Debug::LYXSERVER) << "lyx: Server socket quitting" << endl;
}
-string const & LyXServerSocket::address() const
+string const LyXServerSocket::address() const
{
- return address_;
+ return address_.absFilename();
}
// void LyXServerSocket::dump() const
// {
// lyxerr << "LyXServerSocket debug dump.\n"
-// << "fd = " << fd_ << ", address = " << address_ << ".\n"
+// << "fd = " << fd_ << ", address = " << address_.absFilename() << ".\n"
// << "Clients: " << clients.size() << ".\n";
// std::map<int, shared_ptr<LyXDataSocket> >::const_iterator client = clients.begin();
// std::map<int, shared_ptr<LyXDataSocket> >::const_iterator end = clients.end();
#ifndef LYXSOCKET_H
#define LYXSOCKET_H
+#include "support/filename.h"
#include "support/socktools.h"
#include "lyxfunc.h"
class LyXServerSocket {
public:
///
- LyXServerSocket(LyXFunc *, std::string const &);
+ LyXServerSocket(LyXFunc *, support::FileName const &);
///
~LyXServerSocket();
/// Address of the local socket
- std::string const & address() const;
+ std::string const address() const;
/// To be called when there is activity in the server socket
void serverCallback();
/// To be called when there is activity in the data socket
/// File descriptor for the server socket
int fd_;
/// Stores the socket filename
- std::string address_;
+ support::FileName address_;
/// Maximum number of simultaneous clients
enum {
MAX_CLIENTS = 10
namespace support {
namespace socktools {
-int listen(std::string const &, int)
+int listen(FileName const &, int)
{
return -1;
}
// of error). The first argument is the socket address, the second
// is the length of the queue for connections. If successful, a socket
// special file 'name' will be created in the filesystem.
-int listen(string const & name, int queue)
+int listen(FileName const & name, int queue)
{
int fd; // File descriptor for the socket
sockaddr_un addr; // Structure that hold the socket address
- // We use 'name' to fill 'addr'
- string::size_type len = name.size();
+ // We use 'localname' to fill 'addr'
+ string const localname = name.toFilesystemEncoding();
+ 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 << "' too long."
+ lyxerr << "lyx: Socket address '" << name.absFilename() << "' too long."
<< endl;
return -1;
}
// Synonims for AF_UNIX are AF_LOCAL and AF_FILE
addr.sun_family = AF_UNIX;
- name.copy(addr.sun_path, 107);
+ localname.copy(addr.sun_path, 107);
addr.sun_path[len] = '\0';
// This creates a file descriptor for the socket
// 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
+ lyxerr << "lyx: Could not bind address '" << name.absFilename()
<< "' to socket descriptor: " << strerror(errno) << endl;
::close(fd);
- unlink(FileName(name));
+ unlink(name);
return -1;
}
lyxerr << "lyx: Could not put socket in 'listen' state: "
<< strerror(errno) << endl;
::close(fd);
- unlink(FileName(name));
+ unlink(name);
return -1;
}
#ifndef SOCKTOOLS_H
#define SOCKTOOLS_H
-#include <string>
-
namespace lyx {
namespace support {
+
+class FileName;
+
namespace socktools {
-int listen(std::string const &, int);
+int listen(FileName const &, int);
int accept(int);
} // namespace socktools
int const tmpf = make_tempfile(tmpl.get());
if (tmpf != -1) {
- string const t(tmpl.get());
+ string const t(to_utf8(from_filesystem8bit(tmpl.get())));
#if defined (HAVE_CLOSE)
::close(tmpf);
#elif defined (HAVE__CLOSE)