X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FServerSocket.cpp;h=fb6e3bf75c6abe24c62e7c7b05ad683041b6df74;hb=fb90076e9065018ee0ef9e16bae2a5d9dcc9436d;hp=7940b7fc3886d2e3c5017c8c9894da437f237e32;hpb=299745b635faadcf62340c5f914005244c01bc5b;p=lyx.git diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp index 7940b7fc38..fb6e3bf75c 100644 --- a/src/ServerSocket.cpp +++ b/src/ServerSocket.cpp @@ -41,7 +41,6 @@ using namespace std; using namespace lyx::support; - namespace lyx { // Address is the unix address for the 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,11 +109,6 @@ 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)); @@ -125,14 +124,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,9 +142,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(FuncRequest(LFUN_PARAGRAPH_UPDATE)); + theApp()->dispatch(fr, dr); string const rval = to_utf8(dr.message()); if (dr.error()) client->writeln("ERROR:" + cmd + ':' + rval);