Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Server.cpp « server « moses2 - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de3542eb6a3a5d5b005077735b90fea141951c5e (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
/*
 * Server.cpp
 *
 *  Created on: 1 Apr 2016
 *      Author: hieu
 */
#include <iostream>
#include "../System.h"
#include "Server.h"
#include "Translator.h"
#include "../parameters/ServerOptions.h"

using namespace std;

namespace Moses2
{

Server::Server(ServerOptions &server_options, System &system)
  :m_server_options(server_options)
  ,m_translator(new Translator(*this, system))
{
    m_registry.addMethod("translate", m_translator);
}

Server::~Server()
{
    unlink(m_pidfile.c_str());
}

void Server::run(System &system)
{
  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());

#ifdef _WIN32
  int thePid = GetCurrentProcessId();
#else
  int thePid = getpid();
#endif
  pidfile << thePid << std::endl;
  pidfile.close();
  cerr << "Listening on port " << m_server_options.port << std::endl;
  if (m_server_options.is_serial) {
    cerr << "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;
}

ServerOptions const&Server::options() const
{
  return m_server_options;
}


} /* namespace Moses2 */