X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FServerSocket.cpp;h=fd903ce18fa4f69898da1516ae4d2acb5b2b2602;hb=28be7d552f62cc02fa86d7f79201d089bfb2d7b5;hp=7b9d6df5af71c81d885c36c29045127a2964ae47;hpb=ea3154184833f4f2426eb2a956878e83ddd822d9;p=lyx.git diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp index 7b9d6df5af..fd903ce18f 100644 --- a/src/ServerSocket.cpp +++ b/src/ServerSocket.cpp @@ -26,22 +26,27 @@ #include "support/debug.h" #include "support/environment.h" #include "support/FileName.h" +#include "support/lassert.h" #include "support/socktools.h" -#include "support/bind.h" +#include #include +#include #include #if defined (_WIN32) # include #endif +#ifdef HAVE_UNISTD_H +# include +#endif + using namespace std; using namespace lyx::support; - namespace lyx { // Address is the unix address for the socket. @@ -98,6 +103,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,14 +115,8 @@ 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, bind(&ServerSocket::dataCallback, @@ -125,14 +129,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;