blob: 19073873fac422cb8a28488d45e0bf3a03221dba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
#include "Server.h"
#include <sstream>
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);
}
Server::
~Server()
{
unlink(m_pidfile.c_str());
}
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("*")
.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)
);
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();
XVERBOSE(1,"Listening on port " << m_server_options.port << std::endl);
if (m_server_options.is_serial)
{
VERBOSE(1,"Running server in serial mode." << std::endl);
while(true) myAbyssServer.runOnce();
}
else myAbyssServer.run();
std::cerr << "xmlrpc_c::serverAbyss.run() returned but it should not."
<< std::endl;
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);
}
}
|