* src/support/tempname.C
(tempName): Return FileName in utf8 encoding.
* src/lyxsocket.[Ch]
(LyXServerSocket::LyXServerSocket): Use FileName instead of string
and set the env var LYXSOCKET in the filesystem encoding as this
is what the client expects.
* src/support/socktools.[Ch]
(socktools::listen): Convert to FileName and use the filesystem
encoding for the file names stored in the sockaddr_un struct.
* src/client/client.C
(socktools::connect): Convert to FileName and use the filesystem
encoding for the file names stored in the sockaddr_un struct.
(LyXDataSocket::LyXDataSocket, main): Convert to FileName.
* src/lyx_main.C
(LyX::exec): Use FileName instead of string in socket code.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17749
a592a061-630c-0410-9148-
cb99ea01b6c8
#include <config.h>
#include "debug.h"
#include <config.h>
#include "debug.h"
+#include "support/filename.h"
#include "support/unicode.h"
#include "support/lstrings.h"
#include "support/unicode.h"
#include "support/lstrings.h"
-using lyx::support::prefixIs;
+using support::FileName;
+using support::prefixIs;
using boost::scoped_ptr;
namespace fs = boost::filesystem;
using boost::scoped_ptr;
namespace fs = boost::filesystem;
/// Connect to the socket \p name.
/// 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
{
int fd; // File descriptor for the socket
sockaddr_un addr; // Structure that hold the socket address
+ string const encoded = name.toFilesystemEncoding();
- string::size_type len = name.size();
+ string::size_type len = encoded.size();
if (len > 107) {
cerr << "lyxclient: Socket address '" << name
<< "' too long." << endl;
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;
}
// 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) {
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) {
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;
<< ": " << strerror(errno) << endl;
::close(fd);
return -1;
// Modified LyXDataSocket class for use with the client
class LyXDataSocket {
public:
// 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();
// 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;
{
if ((fd_ = support::socktools::connect(address)) == -1) {
connected_ = false;
scoped_ptr<LyXDataSocket> server;
if (!cmdline::serverAddress.empty()) {
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;
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.
} 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
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 "
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_,
// 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();
// 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.
// 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)
: func(f),
fd_(support::socktools::listen(addr, 3)),
address_(addr)
// Needed by xdvi
support::setEnv("XEDITOR", "lyxclient -g %f %l");
// Needed by lyxclient
// 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_,
theApp()->registerSocketCallback(
fd_,
);
LYXERR(Debug::LYXSERVER) << "lyx: New server socket "
);
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);
}
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;
}
LYXERR(Debug::LYXSERVER) << "lyx: Server socket quitting" << endl;
}
-string const & LyXServerSocket::address() const
+string const LyXServerSocket::address() const
+ return address_.absFilename();
// void LyXServerSocket::dump() const
// {
// lyxerr << "LyXServerSocket debug dump.\n"
// 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();
// << "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
#ifndef LYXSOCKET_H
#define LYXSOCKET_H
+#include "support/filename.h"
#include "support/socktools.h"
#include "lyxfunc.h"
#include "support/socktools.h"
#include "lyxfunc.h"
class LyXServerSocket {
public:
///
class LyXServerSocket {
public:
///
- LyXServerSocket(LyXFunc *, std::string const &);
+ LyXServerSocket(LyXFunc *, support::FileName const &);
///
~LyXServerSocket();
/// Address of the local socket
///
~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
/// 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
/// File descriptor for the server socket
int fd_;
/// Stores the socket filename
+ support::FileName address_;
/// Maximum number of simultaneous clients
enum {
MAX_CLIENTS = 10
/// Maximum number of simultaneous clients
enum {
MAX_CLIENTS = 10
namespace support {
namespace socktools {
namespace support {
namespace socktools {
-int listen(std::string const &, int)
+int listen(FileName const &, int)
// 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.
// 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
{
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) {
// 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;
<< 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
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) {
// 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);
<< "' to socket descriptor: " << strerror(errno) << endl;
::close(fd);
- unlink(FileName(name));
lyxerr << "lyx: Could not put socket in 'listen' state: "
<< strerror(errno) << endl;
::close(fd);
lyxerr << "lyx: Could not put socket in 'listen' state: "
<< strerror(errno) << endl;
::close(fd);
- unlink(FileName(name));
#ifndef SOCKTOOLS_H
#define SOCKTOOLS_H
#ifndef SOCKTOOLS_H
#define SOCKTOOLS_H
namespace lyx {
namespace support {
namespace lyx {
namespace support {
-int listen(std::string const &, int);
+int listen(FileName const &, int);
int accept(int);
} // namespace socktools
int accept(int);
} // namespace socktools
int const tmpf = make_tempfile(tmpl.get());
if (tmpf != -1) {
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)
#if defined (HAVE_CLOSE)
::close(tmpf);
#elif defined (HAVE__CLOSE)