2015-08-04 03:59:28 +03:00
|
|
|
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
|
|
|
#include "Server.h"
|
2015-12-07 19:01:12 +03:00
|
|
|
#include <sstream>
|
|
|
|
|
2015-08-04 03:59:28 +03:00
|
|
|
namespace MosesServer
|
|
|
|
{
|
|
|
|
Server::
|
|
|
|
Server(Moses::Parameter& params)
|
|
|
|
: m_server_options(params),
|
|
|
|
m_updater(new Updater),
|
|
|
|
m_optimizer(new Optimizer),
|
|
|
|
m_translator(new Translator(*this)),
|
|
|
|
m_close_session(new CloseSession(*this))
|
|
|
|
{
|
|
|
|
m_registry.addMethod("translate", m_translator);
|
|
|
|
m_registry.addMethod("updater", m_updater);
|
|
|
|
m_registry.addMethod("optimize", m_optimizer);
|
|
|
|
m_registry.addMethod("close_session", m_close_session);
|
|
|
|
}
|
|
|
|
|
2015-12-07 19:01:12 +03:00
|
|
|
Server::
|
|
|
|
~Server()
|
|
|
|
{
|
|
|
|
unlink(m_pidfile.c_str());
|
|
|
|
}
|
|
|
|
|
2015-08-04 03:59:28 +03:00
|
|
|
int
|
|
|
|
Server::
|
|
|
|
run()
|
|
|
|
{
|
|
|
|
xmlrpc_c::serverAbyss myAbyssServer
|
|
|
|
(xmlrpc_c::serverAbyss::constrOpt()
|
|
|
|
.registryP(&m_registry)
|
|
|
|
.portNumber(m_server_options.port) // TCP port on which to listen
|
|
|
|
.logFileName(m_server_options.logfile)
|
|
|
|
.allowOrigin("*")
|
2015-11-10 23:30:06 +03:00
|
|
|
.maxConn(m_server_options.maxConn)
|
|
|
|
.maxConnBacklog(m_server_options.maxConnBacklog)
|
|
|
|
.keepaliveTimeout(m_server_options.keepaliveTimeout)
|
|
|
|
.keepaliveMaxConn(m_server_options.keepaliveMaxConn)
|
|
|
|
.timeout(m_server_options.timeout)
|
|
|
|
);
|
2015-12-07 19:01:12 +03:00
|
|
|
std::ostringstream pidfilename;
|
|
|
|
pidfilename << "/tmp/moses-server." << m_server_options.port << ".pid";
|
|
|
|
m_pidfile = pidfilename.str();
|
|
|
|
std::ofstream pidfile(m_pidfile.c_str());
|
|
|
|
pidfile << getpid() << std::endl;
|
|
|
|
pidfile.close();
|
2015-08-09 22:52:56 +03:00
|
|
|
XVERBOSE(1,"Listening on port " << m_server_options.port << std::endl);
|
2015-08-04 03:59:28 +03:00
|
|
|
if (m_server_options.is_serial)
|
|
|
|
{
|
2015-08-09 22:52:56 +03:00
|
|
|
VERBOSE(1,"Running server in serial mode." << std::endl);
|
|
|
|
while(true) myAbyssServer.runOnce();
|
2015-08-04 03:59:28 +03:00
|
|
|
}
|
|
|
|
else myAbyssServer.run();
|
2015-08-09 22:52:56 +03:00
|
|
|
|
2015-11-04 21:12:49 +03:00
|
|
|
std::cerr << "xmlrpc_c::serverAbyss.run() returned but it should not."
|
|
|
|
<< std::endl;
|
2015-08-04 03:59:28 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Moses::ServerOptions const&
|
|
|
|
Server::
|
|
|
|
options() const
|
|
|
|
{
|
|
|
|
return m_server_options;
|
|
|
|
}
|
|
|
|
|
|
|
|
Session const&
|
|
|
|
Server::
|
|
|
|
get_session(uint64_t session_id)
|
|
|
|
{
|
|
|
|
return m_session_cache[session_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Server::
|
|
|
|
delete_session(uint64_t const session_id)
|
|
|
|
{
|
|
|
|
return m_session_cache.erase(session_id);
|
|
|
|
}
|
|
|
|
}
|