X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FServerSocket.cpp;h=72a70d4edaac9bcede9ede09fa9d0709055ce3c8;hb=57b69a5efddf9f3c148007322f00dad6c253a2ed;hp=e36b071e3484630d764722380d32dc80afacea90;hpb=62ca7f3ae55ad2e0c395cb554d71afab87de1ee3;p=lyx.git diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp index e36b071e34..72a70d4eda 100644 --- a/src/ServerSocket.cpp +++ b/src/ServerSocket.cpp @@ -28,7 +28,7 @@ #include "support/FileName.h" #include "support/socktools.h" -#include +#include "support/bind.h" #include #include @@ -40,7 +40,6 @@ using namespace std; using namespace lyx::support; -using boost::shared_ptr; namespace lyx { @@ -64,7 +63,7 @@ ServerSocket::ServerSocket(FileName const & addr) theApp()->registerSocketCallback( fd_, - boost::bind(&ServerSocket::serverCallback, this) + bind(&ServerSocket::serverCallback, this) ); LYXERR(Debug::LYXSERVER, "lyx: New server socket " @@ -98,6 +97,11 @@ string const ServerSocket::address() const // is OK and if the number of clients does not exceed MAX_CLIENTS void ServerSocket::serverCallback() { + if (clients.size() >= MAX_CLIENTS) { + writeln("BYE:Too many clients connected"); + return; + } + int const client_fd = socktools::accept(fd_); if (fd_ == -1) { @@ -105,17 +109,11 @@ void ServerSocket::serverCallback() return; } - if (clients.size() >= MAX_CLIENTS) { - writeln("BYE:Too many clients connected"); - return; - } - // Register the new client. - clients[client_fd] = - shared_ptr(new LyXDataSocket(client_fd)); + clients[client_fd] = make_shared(client_fd); theApp()->registerSocketCallback( client_fd, - boost::bind(&ServerSocket::dataCallback, + bind(&ServerSocket::dataCallback, this, client_fd) ); } @@ -125,14 +123,16 @@ void ServerSocket::serverCallback() // if the connection has been closed void ServerSocket::dataCallback(int fd) { - shared_ptr client = clients[fd]; - + map >::const_iterator it = clients.find(fd); + if (it == clients.end()) + return; + shared_ptr client = it->second; string line; - size_t pos; bool saidbye = false; while (!saidbye && client->readln(line)) { // The protocol must be programmed here // Split the key and the data + size_t pos; if ((pos = line.find(':')) == string::npos) { client->writeln("ERROR:" + line + ":malformed message"); continue; @@ -141,8 +141,10 @@ void ServerSocket::dataCallback(int fd) string const key = line.substr(0, pos); if (key == "LYXCMD") { string const cmd = line.substr(pos + 1); + FuncRequest fr(lyxaction.lookupFunc(cmd)); + fr.setOrigin(FuncRequest::LYXSERVER); DispatchResult dr; - theApp()->dispatch(lyxaction.lookupFunc(cmd), dr); + theApp()->dispatch(fr, dr); string const rval = to_utf8(dr.message()); if (dr.error()) client->writeln("ERROR:" + cmd + ':' + rval);